=0){
return url.replace(pattern, '$1' + paramValue + '$2');
}
return url + (url.indexOf('?') > 0 ? '&':'?') + paramName + '=' + paramValue;
});
vendor[appName].getAllTableInstances=(function(){
return dataTableInstances;
});
vendor[appName].removeAllTableInstances=(function(){
dataTableInstances=[];
});
vendor[appName].setTableInstance=(function(instance){
dataTableInstances.push(instance);
});
vendor[appName].getTableInstanceById=(function(id){
var allTables=this.getAllTableInstances();
for (var i=0; i < allTables.length; i++){
if(allTables[i].table_id==id){
return allTables[i];
}}
return false;
});
vendor[appName].getTableInstanceByViewId=(function(viewId){
var allTables=this.getAllTableInstances();
for (var i=0; i < allTables.length; i++){
if(allTables[i].table_view_id==viewId){
return allTables[i];
}}
return false;
});
vendor[appName].removeTableInstanceByViewId=(function(viewId){
var allTables=this.getAllTableInstances();
for (var i=0; i < allTables.length; i++){
if(allTables[i].table_view_id==viewId){
allTables.splice(i, 1);
return true;
}}
return false;
});
vendor[appName].getAllRuleJSInstances=(function(){
return ruleJSInstances;
});
vendor[appName].setRuleJSInstance=(function(table){
var rootElem=table.closest('.supsystic-tables-wrap'),
viewId=table.data('view-id');
ruleJSInstances[viewId]=new ruleJS(rootElem.attr('id'));
ruleJSInstances[viewId].instanceTable=table;
return ruleJSInstances[viewId];
});
vendor[appName].getRuleJSInstance=(function(table){
var allRuleJS=this.getAllRuleJSInstances(),
viewId=table.data('view-id');
if(!allRuleJS[viewId]){
this.setRuleJSInstance(table);
}
return allRuleJS[viewId];
});
vendor[appName].request=(function(route, data){
if(!jQuery.isPlainObject(route)||!('module' in route)||!('action' in route)){
throw new Error('Request route is not specified.');
}
if(!jQuery.isPlainObject(data)){
data={};}
if('action' in data){
throw new Error('Reserved field "action" used.');
}
data.action='supsystic-tables';
var url=window.ajaxurl ? window.ajaxurl:ajax_obj.ajaxurl,
deferred=jQuery.Deferred();
jQuery.post(url, jQuery.extend({}, {
route: route
}, data))
.done(function(response, textStatus, jqXHR){
if(response.success){
deferred.resolve(response, textStatus, jqXHR);
}else{
if(data._maxIter){
retryAjax(deferred, url, route, data, 1, data._maxIter);
}else{
var message=typeof response.message!=='undefined' ? response.message:'There are errors during the request.';
deferred.reject(message, textStatus, jqXHR);
}}
}).fail(function(jqXHR, textStatus, errorThrown){
if(data._maxIter){
retryAjax(deferred, url, route, data, 1, data._maxIter);
}else{
deferred.reject(errorThrown, textStatus, jqXHR);
}});
function retryAjax(def, url, route, data, curIter, maxIter){
jQuery.post(url, jQuery.extend({}, {
route: route
}, data))
.done(function(response, textStatus, jqXHR){
if(response.success){
def.resolve(response, textStatus, jqXHR);
}else{
var message=typeof response.message!=='undefined' ? response.message:'There are errors during the request.';
retryErrorHandler(def, url, route, data, curIter, maxIter, message, textStatus, jqXHR);
}}).fail(function(jqXHR, textStatus, errorThrown){
retryErrorHandler(def, url, route, data, curIter, maxIter, errorThrown, textStatus, jqXHR);
});
}
function retryErrorHandler(def, url, route, data, curIter, maxIter, errorThrown, textStatus, jqXHR){
curIter++;
if(curIter < maxIter){
retryAjax(def, url, route, data, curIter, maxIter);
}else{
def.reject(errorThrown, textStatus, jqXHR);
}}
return deferred.promise();
});
vendor[appName].setTableMobileWidth=(function(isMobile){
jQuery('div .supsystic-tables-wrap').each(function(){
isMobile=(typeof(isMobile)=='undefined' ? true:isMobile);
var ssDiv=jQuery(this),
widthAttr=ssDiv.data('table-width-' + (isMobile ? 'mobile':'fixed'));
if(typeof(widthAttr)!='undefined'){
ssDiv.css('display', (widthAttr=='auto' ? 'inline-block':'')).css('width', widthAttr);
}});
});
vendor[appName].initTablesOnPage=(function(id){
this._initTablesOnPage(id);
});
vendor[appName]._initTablesOnPage=(function(id){
var tables=jQuery(typeof id!='undefined' ? '#supsystic-table-' + id + ':not(.dataTable)':'.supsystic-table');
if(tables.length==0) return;
if(typeof this._initTablesOnPageWoo==='function') this._initTablesOnPageWoo(id);
var self=this,
firstTableId='',
firstTableViewId='',
firstTable='',
firstTableWrapper='',
firstTableFirstRow='';
if(jQuery(window).width() <=991){
self.setTableMobileWidth();
}
tables.each(function(){
self.initializeTable(this, self.showTable, function(table){
if(table.is(':visible')){
self._calculateImages(table);
}else{
table.data('isVisible', setInterval(function(){
if(table.is(':visible')){
clearInterval(table.data('isVisible'));
self._calculateImages(table);
}}, 250));
}
if(table.data('align-by-first-table')){
firstTableId=firstTableId||jQuery('.supsystic-table:first').data('id');
firstTable=firstTable||jQuery('#supsystic-table-' + firstTableId);
firstTableViewId=firstTable.data('view-id');
firstTableWrapper=firstTableWrapper||firstTable.parents('#supsystic-table-' + firstTableViewId);
firstTableFirstRow=firstTable.data('head') ? firstTable.find('thead tr:first-child th'):firstTable.find('tbody tr:first-child td');
if(firstTableViewId!=table.data('view-id')){
var currentTableWrapper=table.parents('#supsystic-table-' + table.data('view-id'));
currentTableWrapper.css({
width: firstTableWrapper.get(0).style.width
});
table.css({
width: firstTable.get(0).style.width
});
currentTableWrapper.find('.supsystic-table').each(function(){
var curTable=jQuery(this),
curTableFirstRow=curTable.data('head') ? curTable.find('thead tr:first-child th'):curTable.find('tbody tr:first-child td');
jQuery.each(curTableFirstRow, function(index, element){
if(firstTableFirstRow[index]){
jQuery(this).width(jQuery(firstTableFirstRow[index]).get(0).style.width);
}});
});
}}
if(table.data('merged')&&table.hasClass('ColWithMergeCellsAlign')){
var mergedData=table.data('merged');
jQuery.each(mergedData, function(index, value){
var rowNumWithMergeCell=value.row;
var numForEq=Number(rowNumWithMergeCell) - 1;
table.find('tbody tr:eq(' + numForEq + ')').closest('tr').addClass('haveMergedCell');
});
self.setCellAttributes(table.parents('.supsystic-tables-wrap:first').find('.DTFC_LeftWrapper, DTFC_RightWrapper, .dataTables_scrollHead, .dataTables_scrollFoot').find('th, td'));
}
if(typeof self.getTableInstanceById(table.data('id')).fnAdjustColumnSizing=='function'){
table.trigger('responsive-resize.dt');
setTimeout(function(){
table.trigger('responsive-resize.dt');
self.getTableInstanceById(table.data('id')).fnAdjustColumnSizing(false);
}, 500);
}
self.initShortcodesInTable(table);
});
});
});
vendor[appName].initShortcodesInTable=(function(table){
var tableViewId=table.data('view-id');
if(typeof(gmpAllMapsInfo)!=='undefined'&&gmpAllMapsInfo&&gmpAllMapsInfo.length){
for (var i=0; i < gmpAllMapsInfo.length; i++){
var mapData=gmpAllMapsInfo[i],
map=jQuery('#' + mapData.view_html_id);
if(map.length&&map.closest('#supsystic-table-' + tableViewId).length){
var mapViewId=mapData.view_id;
setTimeout(function(mapData, mapViewId){
g_gmpAllMaps=jQuery.grep(g_gmpAllMaps, function(value){
if(value.getViewId()==mapViewId){
if(mapData.heatmap&&mapData.heatmap.coords){
var coord=[],
oldCoord=mapData.heatmap.coords;
for (var c=0; c < oldCoord.length; c++){
var data=oldCoord[c];
coord.push(typeof data=='object' ? data.join(','):data);
}
mapData.heatmap.coords=coord;
}
if(value._mapParams.simple_slider_id){
jQuery('#' + value._mapParams.simple_slider_id).html(value._mapParams.original_slider_html);
}}
return value.getViewId()!=mapViewId;
});
gmpInitMapOnPage(mapData);
}, 50, mapData, mapViewId);
}}
jQuery(document).trigger('gmpAmiVarInited');
}
if(typeof(umsAllMapsInfo)!=='undefined'&&umsAllMapsInfo&&umsAllMapsInfo.length){
for (var i=0; i < umsAllMapsInfo.length; i++){
var mapData=umsAllMapsInfo[i],
map=jQuery('#' + mapData.view_html_id);
if(map.length&&map.closest('#supsystic-table-' + tableViewId).length){
var mapViewId=mapData.view_id;
setTimeout(function(mapData, mapViewId){
g_umsAllMaps=jQuery.grep(g_umsAllMaps, function(value){
if(value.getViewId()==mapViewId){
value._mapObj.remove();
}
return value.getViewId()!=mapViewId;
});
umsInitMapOnPage(mapData);
}, 600, mapData, mapViewId);
}}
jQuery(document).trigger('umsAmiVarInited');
}});
vendor[appName]._getOriginalImageSizes=(function(img){
var tempImage=new Image(),
width,
height;
if('naturalWidth' in tempImage&&'naturalHeight' in tempImage){
width=img.naturalWidth;
height=img.naturalHeight;
}else{
tempImage.src=img.src;
width=tempImage.width;
height=tempImage.height;
}
return {
width: width,
height: height
};});
vendor[appName]._calculateImages=(function($table){
var self=this,
$images=$table.find('img');
if($images.length > 0&&/firefox|trident|msie/i.test(navigator.userAgent)){
$images.hide();
jQuery.each($images, function(index, el){
var $img=jQuery(this),
originalSizes=self._getOriginalImageSizes(this);
if($img.closest('td, th').width() < originalSizes.width){
$img.css('width', '100%');
}});
$images.show();
}});
vendor[appName].createSpinner=(function(elem){
elem=typeof(elem)!='undefined' ? elem:false;
if(elem){
var icon=elem.attr('disabled', true).find('.fa');
if(icon){
icon.data('icon', icon.attr('class'));
icon.attr('class', 'fa fa-spinner fa-spin');
}}else{
return jQuery('', {
class: 'fa fa-spinner fa-spin'
});
}});
vendor[appName].deleteSpinner=(function(elem){
var icon=elem.attr('disabled', false).find('.fa');
if(icon){
icon.attr('class', icon.data('icon'));
icon.data('icon', '');
}});
vendor[appName].initializeTable=(function(table, callback, finalCallback, reinit, addInstance){
if(typeof jQuery.fn.dataTable.moment=="undefined"&&typeof moment!=="undefined"){
jQuery.fn.dataTable.moment=function(format, locale, reverseEmpties){
var types=jQuery.fn.dataTable.ext.type;
types.detect.unshift(function(d){
if(d){
if(d.replace){
d=d.replace(/(<.*?>)|(\r?\n|\r)/g, '');
}
d=jQuery.trim(d);
}
if(d===''||d===null){
return 'moment-'+format;
}
return moment(d, format, locale, true).isValid() ?
'moment-'+format :
null;
});
types.order[ 'moment-'+format+'-pre' ]=function(d){
if(d){
if(d.replace){
d=d.replace(/(<.*?>)|(\r?\n|\r)/g, '');
}
d=jQuery.trim(d);
}
return !moment(d, format, locale, true).isValid() ?
(reverseEmpties ? -Infinity:Infinity) :
parseInt(moment(d, format, locale, true).format('x'), 10);
};};
}
if(typeof jQuery.fn.dataTable.ext.order.intl=="undefined"&&typeof window.Intl!=="undefined"){
jQuery.fn.dataTable.ext.order.intl=function(locales, options){
if(window.Intl){
var collator=new Intl.Collator(locales, options);
var types=jQuery.fn.dataTable.ext.type;
delete types.order['string-pre'];
types.order['string-asc']=collator.compare;
types.order['string-desc']=function(a, b){
return collator.compare(a, b) * -1;
};}};}
if(typeof naturalSort=="undefined"){
function naturalSort (a, b, html){
var re=/(^-?[0-9]+(\.?[0-9]*)[df]?e?[0-9]?%?$|^0x[0-9a-f]+$|[0-9]+)/gi,
sre=/(^[ ]*|[ ]*$)/g,
dre=/(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/,
hre=/^0x[0-9a-f]+$/i,
ore=/^0/,
htmre=/(<([^>]+)>)/ig,
x=a.toString().replace(sre, '')||'',
y=b.toString().replace(sre, '')||'';
if(!html){
x=x.replace(htmre, '');
y=y.replace(htmre, '');
}
var xN=x.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'),
yN=y.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'),
xD=parseInt(x.match(hre), 10)||(xN.length!==1&&x.match(dre)&&Date.parse(x)),
yD=parseInt(y.match(hre), 10)||xD&&y.match(dre)&&Date.parse(y)||null;
if(yD){
if(xD < yD){
return -1;
}
else if(xD > yD){
return 1;
}}
for(var cLoc=0, numS=Math.max(xN.length, yN.length); cLoc < numS; cLoc++){
var oFxNcL=parseFloat(xN[cLoc], 10)||xN[cLoc]||undefined;
var oFyNcL=parseFloat(yN[cLoc], 10)||yN[cLoc]||undefined;
if(isNaN(oFxNcL)!==isNaN(oFyNcL)){
return (isNaN(oFxNcL)) ? 1:-1;
}
else if(typeof oFxNcL!==typeof oFyNcL){
oFxNcL +='';
oFyNcL +='';
}
if(oFxNcL < oFyNcL){
return -1;
}
if(oFxNcL > oFyNcL){
return 1;
}}
return 0;
}}
if(typeof jQuery.fn.dataTableExt.oApi.fnFakeRowspan=="undefined"){
jQuery.fn.dataTableExt.oApi.fnFakeRowspan=function (oSettings){
if(oSettings){
var cells;
jQuery.each(oSettings.aoData, function(index, rowData){
vendor[appName].setCellAttributes(rowData.anCells);
});
if(oSettings.aoHeader.length){
cells=[];
jQuery.each(oSettings.aoHeader, function(index, rowData){
jQuery.each(rowData, function(index, cellData){
cells.push(cellData.cell);
});
});
vendor[appName].setCellAttributes(cells);
}
if(oSettings.aoFooter.length){
cells=[];
jQuery.each(oSettings.aoFooter, function(index, rowData){
jQuery.each(rowData, function(index, cellData){
cells.push(cellData.cell);
});
});
vendor[appName].setCellAttributes(cells);
}}
return this;
};}
if(typeof jQuery.fn.dataTableExt.oApi.fnResetFakeRowspan=="undefined"){
jQuery.fn.dataTableExt.oApi.fnResetFakeRowspan=function (oSettings){
if(oSettings){
var displayRows=oSettings.aiDisplay,
mergedData=jQuery(oSettings.nTable).data('merged');
if(!mergedData||mergedData.length==0||displayRows.length==0) return this;
var rows=oSettings.aoData,
table=jQuery(oSettings.nTable),
autoHiding=table.attr('data-auto-hiding'),
rowNums={},
first=table.attr('data-auto-index')=='new' ? 1:0;
autoHiding=(typeof(autoHiding)!='undefined'&&autoHiding.length > 0) ? autoHiding.split(',').map(Number):[];
jQuery.each(displayRows, function(index, rowNum){
var cells=rows[rowNum].anCells;
rowNums[cells[first].getAttribute('data-y')]=rowNum;
for(var i=0; i < cells.length; i++){
if(cells[i].getAttribute('data-hide')=="true"&&(autoHiding.length <=i||autoHiding[i]==1)){
jQuery(cells[i]).css('display', '');
}
cells[i].setAttribute('rowspan', 1);
cells[i].setAttribute('colspan', 1);
}});
jQuery.each(mergedData, function(index, value){
var firstRow=Number(value.row) + 1,
lastRow=firstRow + Number(value.rowspan) - 1,
colspan=Number(value.colspan),
firstCol=Number(value.col) + first,
lastCol=firstCol + colspan - 1,
rowspan=0;
for(var r=firstRow; r <=lastRow; r++){
if(r in rowNums){
if(rowspan==0){
firstRow=r;
}
for(var c=firstCol + (firstRow==r ? 1:0); c <=lastCol; c++){
var cell=rows[rowNums[r]].anCells[c];
if(typeof cell!=="undefined"&&typeof cell.style!=="undefined"&&typeof cell.style.display!=="undefined"){
cell.style.display='none';
}
if(autoHiding[c]===0){
colspan--;
}}
rowspan++;
}}
if(rowspan > 0){
var mergedCell=rows[rowNums[firstRow]].anCells[firstCol];
if(rowspan > 1){
mergedCell.setAttribute('rowspan', rowspan);
}
if(colspan > 1){
mergedCell.setAttribute('colspan', colspan);
}}
});
}
return this;
};}
if(typeof jQuery.fn.dataTableExt.oSort!=="undefined"){
jQuery.extend(jQuery.fn.dataTableExt.oSort, {
"natural-asc": function(a, b){
return naturalSort(a,b,true);
},
"natural-desc": function(a, b){
return naturalSort(a,b,true) * -1;
},
"natural-nohtml-asc": function(a, b){
return naturalSort(a,b,false);
},
"natural-nohtml-desc": function(a, b){
return naturalSort(a,b,false) * -1;
},
"natural-ci-asc": function(a, b){
a=a.toString().toLowerCase();
b=b.toString().toLowerCase();
return naturalSort(a,b,true);
},
"natural-ci-desc": function(a, b){
a=a.toString().toLowerCase();
b=b.toString().toLowerCase();
return naturalSort(a,b,true) * -1;
},
"natural-nohtml-ci-asc": function(a, b){
a=a.toString().toLowerCase();
b=b.toString().toLowerCase();
return naturalSort(a,b,false);
},
"natural-nohtml-ci-desc": function(a, b){
a=a.toString().toLowerCase();
b=b.toString().toLowerCase();
return naturalSort(a,b,false) * -1;
}});
}
reinit=typeof reinit!='undefined' ? reinit:{};
addInstance=typeof addInstance!='undefined' ? addInstance:true;
var self=this,
$table=(table instanceof $ ? table:jQuery(table)),
features=$table.data('features'),
config={},
responsiveMode=$table.data('responsive-mode'),
searchingSettings=$table.data('searching-settings'),
tableInstance={},
defaultFeatures={
autoWidth: false,
info: false,
ordering: false,
paging: false,
responsive: false,
searching: false,
stateSave: false,
bJQueryUI: true,
api: true,
retrieve: true,
processing: true,
initComplete: callback,
headerCallback: function(thead, data, start, end, display){
jQuery(thead).closest('thead').find('th').each(function(){
self.setStylesToCell(this);
});
},
footerCallback: function(tfoot, data, start, end, display){
jQuery(tfoot).closest('tfoot').find('th').each(function(){
self.setStylesToCell(this);
});
},
order: []
};
g_stbServerSideProcessing=$table.data('server-side-processing')&&$table.data('server-side-processing')=='on';
$table.find('tbody td[data-colspan], tbody td[data-rowspan]').each(function(index, item){
var cell=jQuery(item),
cellData=cell.html();
if(!cellData.toString().match(/<.*?id=['|"].*?['|"].*?>/g)){
var cellOrValue=cell.data('original-value'),
cellFormula=cell.data('formula'),
cellOrder=cell.data('order'),
table=cell.parents('table:first'),
colIndex=cell.index(),
rowIndex=cell.parents('tr:first').index(),
colspan=cell.data('colspan'),
rowspan=cell.data('rowspan');
for (var i=rowIndex + 1; i <=rowIndex + rowspan; i++){
for (var j=colIndex + 1; j <=colIndex + colspan; j++){
var hiddenCell=table.find('tbody tr:nth-child(' + i + ') td:nth-child(' + j + ')');
if(hiddenCell.data('hide')&&!$table.data('merged')){
hiddenCell.html(cellData);
hiddenCell.data('original-value', cellOrValue);
hiddenCell.attr('data-original-value', cellOrValue);
hiddenCell.data('order', cellOrder);
hiddenCell.attr('data-order', cellOrder);
if(cellFormula){
hiddenCell.data('formula', cellFormula);
hiddenCell.attr('data-formula', cellFormula);
}}
}}
}});
jQuery.each(features, function(){
var featureName=this.replace(/[-_]([a-z])/g, function(g){
return g[1].toUpperCase();
});
config[featureName]=true;
});
if($table.data('search-value')&&!config['searching']){
config['searching']=true;
}
if(!config['searching']&&(typeof this.setTableAddSearching==='function')){
config['searching']=this.setTableAddSearching($table);
}
if(toeInArray('searching', features)!=-1&&searchingSettings){
if(searchingSettings.minChars > 0 ||
searchingSettings.resultOnly ||
searchingSettings.strictMatching
){
jQuery.fn.dataTable.ext.search.push(function(settings, data){
var $searchInput=jQuery(settings.nTableWrapper).find('.dataTables_filter input'),
searchValue=$searchInput.val();
if(searchingSettings.resultOnly&&searchValue.length===0){
if(searchingSettings.showTable){
return false;
}
return false;
}
if(searchingSettings.strictMatching){
searchValue=jQuery.fn.dataTable.util.escapeRegex(searchValue);
var regExp=new RegExp('^' + searchValue, 'i');
for (var i=0; i < data.length; i++){
var words=data[i].replace(/\s\s+/g, ' ').split(' ');
for (var j=0; j < words.length; j++){
if(words[j].match(regExp)){
return true;
}}
}
return false;
}else{
return data.join(' ').toLowerCase().indexOf(searchValue.toLowerCase())!==-1
}});
$table.on('init.dt', function(event, settings){
if(!settings){
return;
}
var $tableWrapper=jQuery(settings.nTableWrapper),
$tableSearchInput=$tableWrapper.find('.dataTables_filter input'),
$customInput=$tableSearchInput.clone();
$tableSearchInput.replaceWith($customInput);
$customInput.on('input change', function(){
if(!searchingSettings.showTable){
if(searchingSettings.resultOnly&&searchingSettings.minChars&&(this.value.length < searchingSettings.minChars||!this.value.length)){
$table.hide();
$table.parent().find('.dataTables_paginate').hide();
}else{
$table.show();
$table.parent().find('.dataTables_paginate').show();
}}
if(searchingSettings.minChars&&(this.value.length < searchingSettings.minChars&&this.value.length!==0)){
event.preventDefault();
return false;
}
$table.api().draw();
});
if(searchingSettings.resultOnly&&!searchingSettings.showTable){
$table.hide();
$table.parent().find('.dataTables_paginate').hide();
}});
}
if(searchingSettings.columnSearch){
var inputTop=(searchingSettings.columnSearchPosition&&searchingSettings.columnSearchPosition=='top'),
tPosition=inputTop ? 'thead':'tfoot';
if(!$table.find('.stbColumnsSearchWrapper').length){
var headerRow=$table.find('thead tr:first').find('th');
if(headerRow.length){
var searchRow='',
func=inputTop ? 'prepend':'append';
for (var i=0; i < headerRow.length; i++){
var cellItem=jQuery(headerRow[i]),
cellClass='',
cellStyle='';
if(!g_stbServerSideProcessing){
cellStyle=cellItem.is(':visible') ? '':'style="display: none;"';
}
if(cellItem.hasClass('invisibleCell')){
cellClass=' class="invisibleCell"'
}
searchRow +=' | ';
}
searchRow +='
';
if($table.find(tPosition).length==0){
$table.append(jQuery('<' + tPosition + '>'));
}
$table.find(tPosition)[func](searchRow);
}}
if($table.data('auto-index')!=='off'){
jQuery('.stbColumnsSearchWrapper th:first-child input').css({
'visibility': 'hidden'
});
}}
}
if(toeInArray('ordering', features)!=-1){
var sortingEnable=['_all'],
sortingDisable=[],
aaSorting=[],
multipleSorting=$table.data('multiple-sorting'),
disableSorting=$table.data('disable-sorting');
if(!$table.data('head')){
sortingDisable=['_all'];
}
if(disableSorting&&disableSorting.length){
sortingDisable=disableSorting;
}
if(multipleSorting&&multipleSorting.length){
aaSorting=multipleSorting;
}else{
var columnsCount=$table.find('tr:first th').length,
sortColumn=$table.data('sort-column')||0,
sortOrder=$table.data('sort-order')||'asc',
columnNumber=sortColumn - 1;
if(columnNumber >=0&&columnNumber < columnsCount){
aaSorting.push([columnNumber, sortOrder]);
}}
config.aoColumnDefs={};
config.aaSorting=aaSorting;
delete defaultFeatures.order;
}
if($table.data('pagination-length')){
var paginationLength=String($table.data('pagination-length'));
config.aLengthMenu=[];
config.aLengthMenu.push(paginationLength.replace('All', -1).split(',').map(Number));
config.aLengthMenu.push(paginationLength.split(','));
}
if($table.data('auto-index')&&$table.data('auto-index')!=='off'){
$table.on('draw.dt', function(){
var isFirst=true,
index=1;
$table.api().column(0).nodes().each(function(cell, i){
var style=window.getComputedStyle(cell);
if(isFirst){
index=i + 1;
isFirst=false;
}
if(style.display!=='none'&&!cell.classList.contains('invisibleCell')){
cell.innerHTML=index;
index++;
}});
});
}
if(responsiveMode==0){
var labelStyles='';
$table.append(labelStyles);
jQuery(window).on('load resize orientationchange', $table, function(event){
event.preventDefault();
clearTimeout($table.data('resizeTimer'));
$table.data('resizeTimer', setTimeout(function(){
$table.removeClass('oneColumn oneColumnWithLabels');
$table.css('width', '100%');
var tableWidth=$table.width(),
wrapperWidth=$table.closest('.supsystic-tables-wrap').width();
if(tableWidth > wrapperWidth||jQuery(window).width() <=475){
$table.addClass('oneColumn');
if($table.data('head')=='on'){
$table.addClass('oneColumnWithLabels');
}}
}, 150));
if(g_stbServerSideProcessing){
$table.find('td').each(function(){
jQuery(this).css({
'width': '',
'min-width': ''
});
});
}});
}else if(responsiveMode===1){
config.responsive={
details: {
renderer: function(api, rowIdx, columns){
var $table=jQuery(api.table().node()),
$subTable=jQuery('');
jQuery.each(columns, function(i, col){
if(col.hidden){
var $cell=jQuery(api.cell(col.rowIndex, col.columnIndex).node()).clone(),
markup='';
if($table.data('head')=='on'){
var tableHeadTr=jQuery(api.table().header()).find('tr:not(.stbColumnsSearchWrapper)').eq(0);
var $headerContent=tableHeadTr.find('th').eq(col.columnIndex).html();
markup +='';
if($headerContent){
markup +=$headerContent;
}
markup +=' | ';
}
markup +='
';
$cell.after(jQuery('')
.addClass('collapsed-cell-holder')
.attr('data-cell-row', col.rowIndex)
.attr('data-cell-column', col.columnIndex)
.hide()
);
$subTable.append(jQuery(markup).append($cell.addClass('collapsed').show()));
}});
return $subTable.is(':empty') ? false:$subTable;
}}
};
$table.on('responsive-resize.dt', function(event, api, columns){
if(typeof api=='undefined'||typeof columns=='undefined'){
var tbl=jQuery(this),
instance=vendor[appName].getTableInstanceById(tbl.data('id'));
if(instance){
api=typeof api!='undefined' ? api:instance.api();
columns=typeof columns!='undefined' ? columns:instance.api().columns();
}}
var autoHiding=[],
searchColumn=$table.find('.stbColumnsSearchWrapper input.search-column');
for (var i=0, len=columns.length; i < len; i++){
autoHiding[i]=columns[i] ? 1:0;
}
$table.find('th input.search-column').each(function(){
var th=jQuery(this).parents('th:first'),
i=th.index();
if(columns.length > i){
th.css('display', columns[i] ? '':'none');
}});
if(typeof columns[0]=='boolean'){
$table.attr('data-auto-hiding', autoHiding.join());
}
if($table.width() > $table.parent().width()){
$table.css('width', '100%');
$table.css('max-width', '100%');
api.responsive.recalc();
return;
}
for (var i=0, len=columns.length; i < len; i++){
if(columns[i]){
$table.find('tr > td.collapsed-cell-holder[data-cell-column="' + i + '"]').each(function(index, el){
var $this=jQuery(this);
var $cell=jQuery(api.cell($this.data('cell-row'),
$this.data('cell-column')
).node());
if($cell.hasClass('collapsed')){
$cell.removeClass('collapsed');
$this.replaceWith($cell);
}});
}}
if($table.data('merged')){
$table.find('td[data-hide]').show();
$table.find('td[data-rowspan]').attr({
'data-rowspan': 1,
rowspan: 1,
'data-colspan': 1,
colspan: 1
});
}});
}else if(responsiveMode===2){
config.scrollX=true;
config.bAutoWidth=false;
var firstRow=$table.find('tbody tr:first-child td');
if(firstRow.length){
var cntCols=firstRow.length;
$table.find('thead tr:first-child th').each(function(i, th){
if(cntCols > i&&jQuery(th).css('width')){
firstRow.eq(i).css('width', jQuery(th).css('width'));
}});
}}
if(responsiveMode===2||responsiveMode===3){
var fixedHead=$table.data('head')&&$table.data('fixed-head'),
fixedFoot=$table.data('foot')&&$table.data('fixed-foot'),
fixedLeft=$table.data('fixed-left'),
fixedRight=$table.data('fixed-right');
if(fixedHead||fixedFoot){
config.scrollY=$table.data('fixed-height');
config.scrollCollapse=true;
}
if($table.data('fixed-cols')){
config.fixedColumns={
leftColumns: fixedLeft ? parseInt(fixedLeft):0,
rightColumns: fixedRight ? parseInt(fixedRight):0
};
config.scrollX=true;
}}
var langData=typeof g_stbTblLangData!='undefined' ? JSON.parse(g_stbTblLangData):$table.data('translation'),
translation=langData||{},
override=$table.data('override');
if(typeof translation!='object'){
translation={};}
jQuery.each(override, function(key, value){
if(value.length){
if(key=='previous'||key=='next'){
if(typeof translation['paginate']==="undefined"){
translation['paginate']={};}
translation['paginate'][key]=value;
}
translation[key]=value;
translation['s' + key.charAt(0).toUpperCase() + key.substr(1)]=value;
}});
config.language=translation;
var ajaxSource={};
if(g_stbServerSideProcessing){
var nonce=(typeof DTGS_NONCE!=="undefined") ? DTGS_NONCE:DTGS_NONCE_FRONTEND;
var route={
"action": "getPageRows",
"module": "tables",
"nonce": nonce
},
loadedRows=[],
loadedCells=[],
headerRowsCount=($table.data('head')=='on' ? $table.data('head-rows-count'):0),
footerRowsCount=($table.data('foot')=='on' ? $table.data('foot-custom-rows-count'):0);
ajaxSource={
processing: true,
serverSide: true,
ajax: {
url: window.ajaxurl ? window.ajaxurl:ajax_obj.ajaxurl,
type: 'POST',
data: {
action: "supsystic-tables",
route: route,
id: $table.data('id'),
searchParams: searchingSettings,
searchValue: function(){
var input=jQuery('#' + $table.attr('id') + '_filter.dataTables_filter').find('input');
return (input.length ? input.val():'');
},
header: headerRowsCount,
footer: footerRowsCount,
beforeSend: function(){
g_stbServerSideProcessingIsActive=true;
}},
dataFilter: function(data){
var json=jQuery.parseJSON(data),
rows=jQuery(json.rows).find('tr'),
aData=[];
loadedRows=[];
loadedCells=[];
for (var i=0; i < rows.length; i++){
var row=rows[i];
loadedRows.push(row.attributes);
var cells=jQuery(row).find('td'),
attrs=[],
vals=[];
for (var j=0; j < cells.length; j++){
var cell=cells[j];
attrs.push(cell.attributes);
vals.push(cell.innerHTML);
}
loadedCells.push(attrs);
aData.push(vals);
}
json.rows='';
json.data=aData;
g_stbServerSideProcessingIsActive=false;
return JSON.stringify(json);
}},
createdRow: function(row, data, dataIndex){
if(typeof(loadedRows[dataIndex])!='undefined'){
jQuery(loadedRows[dataIndex]).each(function(){
jQuery(row).attr(this.name, this.value);
});
}}
};
if(typeof(config.aoColumnDefs)=='undefined'||jQuery.isEmptyObject(config.aoColumnDefs)){
config.aoColumnDefs=[];
}
config.aoColumnDefs.push({
targets: '_all',
cellType: 'td',
createdCell: function(td, cellData, rowData, row, col){
if(typeof(loadedCells[row][col])!='undefined'){
var rowspan=1,
colspan=1;
jQuery(loadedCells[row][col]).each(function(){
if(this.name=='data-rowspan'&&this.value > 1){
rowspan=this.value;
}
if(this.name=='data-colspan'&&this.value > 1){
colspan=this.value;
}});
if(rowspan > 1||colspan > 1){
var stopRow=row + parseInt(rowspan),
stopCol=col + parseInt(colspan),
startRow=colspan > 1 ? row:row + 1,
hide;
if(stopRow >=loadedCells.length){
stopRow=loadedCells.length;
}
if(stopCol >=loadedCells[row].length){
stopCol=loadedCells[row].length;
}
for (i=startRow; i < stopRow; i++){
if(i > row){
hide=document.createAttribute('data-hide');
hide.value='true';
loadedCells[i][col].setNamedItem(hide);
}
for (j=col + 1; j < stopCol; j++){
hide=document.createAttribute('data-hide');
hide.value='true';
loadedCells[i][j].setNamedItem(hide);
}}
}
jQuery(loadedCells[row][col]).each(function(){
jQuery(td).attr(this.name, this.value);
});
}}
});
}
window.table=$table;
$table.trigger('beforeInitializeTable', $table);
var dateFormat=$table.data('date-format');
$table.dataTable.moment(dateFormat);
jQuery.fn.dataTable.ext.order.intl();
tableInstance=$table.dataTable(jQuery.extend({}, defaultFeatures, config, extraConfig, ajaxSource, reinit));
tableInstance.table_id=$table.data('id');
tableInstance.table_view_id=$table.data('view-id');
if(typeof tableInstance.fnFakeRowspan!=="undefined"){
tableInstance.fnFakeRowspan();
}
self._checkOnClickPopups($table);
window.table=$table;
if($table.data('remove-rows')){
jQuery(function(){
jQuery.contextMenu({
selector: '.dataTable td',
animation: {
duration: 250,
show: 'fadeIn',
hide: 'fadeOut'
},
callback: function(key, options){
var m="clicked: " + key;
},
items: {
"remove_row": {
name: "Remove row",
callback: function(itemKey, opt, e){
contextMenuAction(this, 'remove_row');
}},
"add_row_before": {
name: "Add row before",
callback: function(itemKey, opt, e){
contextMenuAction(this, 'add_row', 'before');
}},
"add_row_after": {
name: "Add row after",
callback: function(itemKey, opt, e){
contextMenuAction(this, 'add_row', 'after');
}},
"sep1": "---------",
"quit": {
name: "Quit"
}}
});
function contextMenuAction(e, action, second){
var coltext=e.text();
var colvindex=e.parent().children().index(e);
var colindex=jQuery('table.dataTable thead tr th:eq(' + colvindex + ')').data('column-index');
var giCount=1;
switch (action){
case "remove_row":
$table.fnDeleteRow(e.parent('tr'));
$table.fnUpdate();
break;
case "add_row":
var tr=e.parent('tr').clone(true, true);
tr.find('td').html('').addClass('menu-injected').addClass('editable').addClass('justCloned');
tr.find('td').data('original-value', '').attr('data-original-value', '');
var order=tr.find('td').data('order');
if(second=='before'){
order=order - 1;
tr.find('td').data('order', order).attr('data-order', order);
}else{
order=order + 1;
tr.find('td').data('order', order).attr('data-order', order);
}
tr.find('td').data('cell-type', 'text').attr('data-cell-type', 'text');
tr.find('td').data('cell-format-type', '').attr('data-cell-format-type', '');
$table.append(tr);
$table.fnAddData(tr, true);
tr.find('td.justCloned').data('y', '9999').attr('data-y', '9999').removeClass('justCloned');
break;
}}
});
}
if(g_stbServerSideProcessing){
jQuery('.dataTables_processing').css('z-index', '10');
}else{
self.setColumnSearch($table);
}
$table.on('draw.dt', function(){
var searching=$table.data('searching-settings');
if(searching&&('columnSearch' in searching)&&searching.columnSearch=='on'){
self.setColumnSearch($table);
}
if(!g_stbServerSideProcessing&&$table.data('merged')){
tableInstance.fnResetFakeRowspan();
}
self.initShortcodesInTable($table);
});
if(responsiveMode===1){
$table.on('responsive-resize.dt', function(event, api, columns){
if(!g_stbServerSideProcessing&&$table.data('merged')){
tableInstance.fnResetFakeRowspan();
}});
}
if(typeof $table.data('fixed-cols')!=='undefined'){
tableInstance.api().fixedColumns().update();
}
if(addInstance){
this.setTableInstance(tableInstance);
}
return typeof finalCallback=="function" ? finalCallback(tableInstance):tableInstance;
});
vendor[appName].showTable=(function(settings, json){
var self=vendor[appName],
$table=this instanceof $ ? this:settings,
$tableWrap=$table.closest('.supsystic-tables-wrap'),
tableSelector='#supsystic-table-' + $table.data('view-id') + ' #supsystic-table-' + $table.data('id'),
afterTableLoadedScriptString=$table.attr('data-after-table-loaded-script'),
_ruleJS=self.setRuleJSInstance($table),
responsiveMode=$table.data('responsive-mode'),
fixedHeader=$table.data('fixed-head')=='on',
fixedFooter=$table.data('fixed-foot')=='on',
fixedColumns=$table.data('fixed-right') > 0||$table.data('fixed-left') > 0,
viewId=$table.data('view-id');
$table.find('th, td').each(function(){
self.setStylesToCell(this);
});
$table.bind('column-visibility.dt draw.dt', function(e){
jQuery(this).find('th, td').each(function(){
self.setStylesToCell(this);
});
});
if(!$table.data('head')){
$table.find('th').removeClass('sorting sorting_asc sorting_desc sorting_disabled');
}
_ruleJS.init();
self.formatDataAtTable($table, true);
if($table.data('search-value')){
$table.api().search($table.data('search-value')).draw();
}
if('ontouchstart' in window||navigator.msMaxTouchPoints){
$table.parents('.supsystic-tables-wrap:first').find('td, th').on('click', self.applyMobileTableComments);
}
$table.parents('.supsystic-tables-wrap:first').find('th, td').each(self._contactFormBtnCellClb);
$table.on('page.dt', function(){
if(g_stbServerSideProcessing){
g_stbServerSideProcessingIsActive=true;
}
var table=jQuery(this),
tableSelector='#supsystic-table-' + table.data('view-id') + ' #supsystic-table-' + table.data('id');
self.applyTableEventClb(self.pageEvent, 50, tableSelector);
if($table.data('pagination-scroll')=='on'){
jQuery('html, body').animate({
scrollTop: table.closest('.dataTables_wrapper').offset().top
}, 100);
}
if(typeof(self.setImgLightbox)=='function'){
self.setImgLightbox($table);
}});
if(typeof(self.createEditableFields)=='function'){
var $editableFields=$tableWrap.find('.editable'),
$editfileFields=$tableWrap.find('.editfile'),
$selectableFields=$tableWrap.find('.selectable'),
$tableId=$table.data('id'),
useEditableFields=typeof(useEdit)!='undefined'&&typeof(useEdit[$tableId])!='undefined' ?
useEdit[$tableId] :
false;
if(useEditableFields||(SDT_DATA.isAdmin&&SDT_DATA.isPro)){
if(typeof(self.setFrontendFields)=='function'){
self.setFrontendFields($table);
}else if(typeof(self.setAllFields)=='function'){
self.setAllFields($table, $editableFields, $selectableFields);
}else{
self.createEditableFields($table, $editableFields);
self.createEditableFileFields($table, $editfileFields);
}
$table.on('init.dt', function(){
$table.on('responsive-resize.dt responsive-display.dt draw.dt', function(){
$editableFields.off('click.sup');
$editfileFields.off('click.sup');
self.updateAfterRedraw($table);
});
});
}}
if(typeof(self.setImgLightbox)=='function'){
self.setImgLightbox($table);
}
var paginationSelect=$tableWrap.find('.dataTables_length select');
if(paginationSelect.length){
paginationSelect.on('change', function(){
$table.trigger('page.dt');
});
}
self.applyTableEventClb(self.fixHeaderOfHiddenColumns, 50, tableSelector);
$table.trigger('beforeShowTable', $table);
$tableWrap.prev('.supsystic-table-loader').hide();
$tableWrap.css('visibility', 'visible');
self.fixSortingForMultipleHeader($table);
if(responsiveMode===2||fixedHeader||fixedFooter){
jQuery(window).on('load resize orientationchange', $table, function(event){
var tBody=$tableWrap.find('.dataTables_scrollBody'),
tBodyTable=tBody.find('.supsystic-table');
if(tBody.width() > tBodyTable.width()||$tableWrap.width() > tBodyTable.width()){
tBody.width(tBodyTable.width());
$tableWrap.find('.dataTables_scrollHead, .dataTables_scrollFoot, .dataTables_scrollBody').width(tBodyTable.width() + 1);
}
if(tBody.isHorizontallyScrollable()){
tBody.css({
'border-bottom': 'none'
});
}else{
tBody.removeStyle('border-bottom');
}
var table=self.getTableInstanceById($table.data('id'));
if(typeof table.fnAdjustColumnSizing=='function'){
setTimeout(function(){
table.fnAdjustColumnSizing(false);
}, 350);
}});
var tBody=$tableWrap.find('.dataTables_scrollBody'),
tBodyTable=tBody.find('.supsystic-table');
if(tBodyTable.is(":visible")){
setTimeout(function(){
jQuery(window).trigger('load');
}, 200);
}
var $tHeadTable=$tableWrap.find('.dataTables_scrollHead .supsystic-table');
if($tHeadTable.length){
self.formatDataAtTable($tHeadTable, true);
}
var $tFootTable=$tableWrap.find('.dataTables_scrollFoot .supsystic-table');
if($tFootTable.length){
self.formatDataAtTable($tFootTable, true);
}}
if(fixedHeader||fixedFooter){
$table.api().fixedHeader.adjust();
var i=1;
setTimeout(function(){
var flag=fixedHeader,
el=fixedHeader ?
$tableWrap.find('.dataTables_scrollHead table thead tr:first-child th') :
$tableWrap.find('.dataTables_scrollFoot table tfoot tr:first-child th');
el.each(function(){
var thWidth=$tableWrap.find('.dataTables_scrollBody table tbody tr:first-child td:nth-child(' + i + ')');
jQuery(this).css({
'width': thWidth.outerWidth(),
'min-width': thWidth.outerWidth(),
'box-sizing': 'border-box'
});
if(fixedFooter&&flag){
var footerEl=$tableWrap.find('.dataTables_scrollFoot table tfoot tr:first-child th:nth-child(' + i + ')');
footerEl.css({
'width': thWidth.outerWidth(),
'min-width': thWidth.outerWidth(),
'box-sizing': 'border-box'
});
}
i++;
});
}, 200);
}
if(fixedColumns){
$table.api().fixedColumns().relayout();
}
if(!fixedHeader&&!fixedFooter&&responsiveMode===2&&toeInArray('auto_width', $table.data('features'))==-1){
$tableWrap.find('.dataTables_scrollBody table thead tr:first-child th').each(function(){
var tableWidth=$table.width(),
tableWrapWidth=$tableWrap.width();
if(tableWrapWidth > tableWidth){
$tableWrap
.find('.dataTables_scrollHeadInner, .dataTables_scrollBody, .dataTables_scrollFootInner')
.addClass('fit-content');
}});
}
if(afterTableLoadedScriptString!==undefined){
afterTableLoadedScriptString=afterTableLoadedScriptString.substring(1, afterTableLoadedScriptString.length - 1);
var afterTableLoadedScript=b64DecodeUnicode(afterTableLoadedScriptString).replace(/"/g, "'"),
executeScript=new Function(afterTableLoadedScript);
if(typeof executeScript==="function"){
setTimeout(function(){
executeScript();
}, 1000);
}}
if(g_stbServerSideProcessing){
$table.on('draw.dt', function(e){
var searching=$table.data('searching-settings');
if(searching&&('columnSearch' in searching)&&searching.columnSearch=='on'){
self.setColumnSearch($table);
}
self.getTableInstanceByViewId(viewId).fnFakeRowspan();
if(responsiveMode===0||responsiveMode===2){
jQuery(window).trigger('load');
}}).trigger('draw.dt');
}
var tblEditLink='g_stbTblEditLink_' + $table.data('id'),
showTblEditLink=eval("typeof " + tblEditLink)!=='undefined' ? jQuery(window.atob(eval(tblEditLink))):false;
if(showTblEditLink&&jQuery(tableSelector).closest('.supsystic-tables-wrap').find('.tblEditLink').length===0){
jQuery(tableSelector).closest('.supsystic-tables-wrap').append(showTblEditLink);
}
function b64DecodeUnicode(str){
return decodeURIComponent(Array.prototype.map.call(atob(str), function(c){
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
}});
vendor[appName].applyTableEventClb=(function(clb, timeout){
timeout=timeout ? timeout:0;
var self=this,
args=Array.from(arguments);
if(g_stbServerSideProcessing&&g_stbServerSideProcessingIsActive){
setTimeout(function(){
self.applyTableEventClb.apply(self, args);
}, 50);
}else{
if(typeof clb=='function'){
args=args.slice(2);
setTimeout(function(){
clb.apply(self, args);
}, timeout);
}}
});
vendor[appName].pageEvent=(function(tableSelector){
var table=jQuery(tableSelector),
tableWrapper=table.parents('.supsystic-tables-wrap:first');
this.getRuleJSInstance(table).init();
this.formatDataAtTable(table, true);
this.fixHeaderOfHiddenColumns(table);
if('ontouchstart' in window||navigator.msMaxTouchPoints){
tableWrapper.find('td, th').on('click', this.applyMobileTableComments);
}
tableWrapper.find('td, th').each(this._contactFormBtnCellClb);
this.initShortcodesInTable(table);
});
vendor[appName].fixHeaderOfHiddenColumns=(function($table){
$table=$table instanceof $ ? $table:jQuery($table);
var tableWrapper=$table.parents('.supsystic-tables-wrap:first');
if(!$table.data('head')){
tableWrapper.find('thead').each(function(){
var thead=jQuery(this);
thead.find('th').each(function(iter, item){
var th=jQuery(this),
itemIndex=iter + 1,
columnAllTd=thead.parents('table:first').find('tbody td:nth-child(' + itemIndex + ')'),
columnInvTd=columnAllTd.filter('.invisibleCell'),
hidden=columnAllTd.length > 0&&columnAllTd.length==columnInvTd.length;
if(hidden){
th.addClass('invisibleCell');
}});
});
}});
vendor[appName].applyMobileTableComments=(function(e){
var $elem=jQuery(this),
title=$elem.attr('title');
if(title){
var tableViewId=$elem.parents('table.supsystic-table:first').data('view-id'),
cellId=$elem.data('cell-id'),
comment=jQuery('.stbMobileComment[data-table="' + tableViewId + '"][data-cell="' + cellId + '"]');
if(!comment.length){
comment=jQuery('');
comment.text(title)
.data('table', tableViewId)
.attr('data-table', tableViewId)
.data('cell', cellId)
.attr('data-cell', cellId)
.appendTo('body');
}
comment.css({
top: (e.pageY - 70) + 'px',
left: (e.pageX + 20) + 'px'
}).fadeIn('slow');
setTimeout(function(){
comment.fadeOut('slow');
}, 2500);
}});
vendor[appName]._contactFormBtnCellClb=(function(e){
var cell=jQuery(this),
y=cell.data('y'),
pair,
valueCell;
if(cell.html().indexOf('cfsPreFill')!=-1){
var cellHtml=cell.html().replace(/href=["|']([^"]*?)["|']/g, function(a, b){
if(b.indexOf('cfsPreFill')!=-1){
var newB=b.split('&');
if(newB.length){
for (var i=0; i < newB.length; i++){
pair=newB[i].split('=');
if(pair.length&&pair[1].match(/[A-Za-z]/)){
valueCell=cell.parents('tr:first').find('[data-cell-id="' + pair[1] + y + '"]');
if(valueCell.length){
pair[1]=jQuery.trim(valueCell.html());
}}
newB[i]=pair.join('=');
}
newB=newB.join('&');
a=a.replace(b, newB);
}
return a;
}});
cell.html(cellHtml);
}});
vendor[appName].setColumnSearch=(function(table){
if(typeof this.setTableAddFilters==='function') this.setTableAddFilters(table);
var self=this,
searchingSettings=table.data('searching-settings'),
inputs=table.parents('.dataTables_wrapper:first').find('.stbColumnsSearchWrapper .search-column');
if(inputs.length==0){
return;
}
inputs.off('keyup.dtg change.dtg').on('keyup.dtg change.dtg', function(){
var input=jQuery(this),
position=input.parents('th:first').index(),
value=this.value,
column=table.api().column(position);
if(typeof self.resetTableAddFilters==='function') self.resetTableAddFilters(table);
if(column.search()!==value){
column.search(value.replace(/;/g, "|"), true, false).draw();
setTimeout(function(){
column.draw();
}, 50);
}});
});
vendor[appName].setCopyEvents=(function(obj, events){
jQuery.each(events, function(event, handlers){
jQuery.each(handlers, function(j, handler){
jQuery(obj).unbind(event).bind(event, handler);
});
});
});
vendor[appName].executeScript=(function(table){
var $table=(table instanceof $ ? table:jQuery(table)),
$tableWrap=$table.closest('.supsystic-tables-wrap');
this.getRuleJSInstance($table).init();
$tableWrap.prev('.supsystic-table-loader').hide();
$tableWrap.css('visibility', 'visible');
});
vendor[appName].fixSortingForMultipleHeader=(function(table){
if(table.data('head-rows-count') > 1&&table.data('sort-order')){
var thead=table.find('thead tr').get().reverse();
if(table.data('head')){
jQuery.each(table.find('thead tr:last-child th'), function(index, element){
var th=jQuery(element),
nthChild=index + 1;
if(th.data('hide')){
jQuery(thead).each(function(){
var item=jQuery(this).find('th:nth-child(' + nthChild + ')');
if(!item.data('hide')){
item.addClass('sorting');
item.click(function(){
th.trigger('click');
if(th.hasClass('sorting')){
item.removeClass('sorting_asc');
item.removeClass('sorting_desc');
item.addClass('sorting');
}else if(th.hasClass('sorting_asc')){
item.removeClass('sorting');
item.removeClass('sorting_desc');
item.addClass('sorting_asc');
}else if(th.hasClass('sorting_desc')){
item.removeClass('sorting');
item.removeClass('sorting_asc');
item.addClass('sorting_desc');
}});
return false;
}});
}});
}}
});
vendor[appName].formatDataAtTable=(function(table, correctSorting){
correctSorting=correctSorting ? correctSorting:false;
var self=this,
numberFormat=table.data('number-format'),
generalCurrencyFormat=table.data('currency-format'),
generalPercentFormat=table.data('percent-format'),
generalDateFormat=table.data('date-format'),
generalTimeFormat=table.data('time-format');
table.find('th, td').each(function(index, el){
var $this=jQuery(this);
if((table.data('auto-index')!='off'&&$this.is(':first-child')) ||
(table.data('responsive-mode')==1&&table.hasClass('collapsed')&&$this.hasClass('child')) ||
$this.find('.search-column').length ||
$this.hasClass('tooltipCell') ||
$this.data('hide')
){
return;
}
var languageData=numeral.languageData(),
format=$this.data('cell-format'),
formatType=$this.data('cell-format-type'),
preparedFormat,
delimiters,
value=jQuery.trim($this.html()),
noFormat=false;
if(correctSorting&&toeInArray(formatType, ['date', 'time_duration'])==-1){
var dataTableInstance=typeof table.api=='function' ? table:self.getTableInstanceById(table.data('id'));
if($this.data('original-value')!=value){
$this.data('original-value', value);
$this.attr('data-original-value', value);
}
if($this.data('data-order')!=value){
$this.data('order');
$this.attr('data-order', value);
if(dataTableInstance){
dataTableInstance.api().cell($this).invalidate();
}}
}
if(value){
if($this.data('cell-reformat')){
switch (formatType){
case 'date':
var newDate=moment(value, format);
if(newDate.isValid()){
value=newDate.format(generalDateFormat);
$this.data('cell-format', generalDateFormat);
$this.attr('data-cell-format', generalDateFormat);
$this.data('original-value', value);
$this.attr('data-original-value', value);
$this.data('order', value);
$this.attr('data-order', value);
if(!g_stbServerSideProcessing){
$this.data('cell-reformat', false);
$this.attr('data-cell-reformat', 0);
}}
break;
case 'time_duration':
var newTime=moment(value, format),
isValid=false;
if(newTime.isValid()){
value=newTime.format(generalTimeFormat);
isValid=true;
}else{
newTime=moment.duration(value);
if(newTime._milliseconds||value==0){
value=newTime.format(generalTimeFormat);
isValid=true;
}}
if(isValid){
$this.data('cell-format', generalTimeFormat);
$this.attr('data-cell-format', generalTimeFormat);
$this.data('original-value', value);
$this.attr('data-original-value', value);
$this.data('order', value);
$this.attr('data-order', value);
if(!g_stbServerSideProcessing){
$this.data('cell-reformat', false);
$this.attr('data-cell-reformat', 0);
}}
break;
default:
break;
}}else if(self.isNumber(value)&&!isNaN(value)){
numberFormat=numberFormat ? numberFormat.toString():'';
switch (formatType){
case 'percent':
format=format ? format:generalPercentFormat;
if(format){
format=format.toString();
var clearFormat=format.indexOf('%') > -1 ? format.replace('%', ''):format;
value=value.indexOf('%') > -1 ? $this.data('original-value'):value;
delimiters=(clearFormat.match(/[^\d]/g)||[',', '.']).reverse();
languageData.delimiters={
decimal: delimiters[0],
thousands: delimiters[1]
};
preparedFormat=format.replace(clearFormat, clearFormat.replace(delimiters[0], '.').replace(delimiters[1], ','));
}else{
noFormat=true;
}
break;
case 'currency':
format=format ? format:generalCurrencyFormat;
if(format){
format=format.toString();
var formatWithoutCurrency=format.match(/\d.?\d*.?\d*/)[0],
currencySymbol=format.replace(formatWithoutCurrency, '')||'$';
delimiters=(formatWithoutCurrency.match(/[^\d]/g)||[',', '.']).reverse();
languageData.delimiters={
decimal: delimiters[0],
thousands: delimiters[1]
};
languageData.currency.symbol=currencySymbol;
preparedFormat=format
.replace(formatWithoutCurrency, formatWithoutCurrency
.replace(delimiters[0], '.')
.replace(delimiters[1], ','))
.replace(currencySymbol, '$');
}else{
noFormat=true;
}
break;
case 'date':
case 'time_duration':
noFormat=true;
break;
default:
if(numberFormat){
format=numberFormat;
delimiters=(format.match(/[^\d]/g)||[',', '.']).reverse();
languageData.delimiters={
decimal: delimiters[0],
thousands: delimiters[1]
};
preparedFormat=format.replace(format, format.replace(delimiters[0], '.').replace(delimiters[1], ','));
break;
}else{
noFormat=true;
}
break;
}
if(noFormat){
noFormat=false;
}else{
numeral.language('en', languageData);
value=numeral(value).format(preparedFormat);
}}
}
$this.html(value);
});
});
vendor[appName].isNumber=(function(value){
if(value){
if(value.toString().match(/^-{0,1}\d+\.{0,1}\d*$/)){
return true;
}}
return false;
});
vendor[appName].prepareFormulaToParse=(function(value){
var stringsInFormula=value.match(/".+?"|'.+?'/g);
if(stringsInFormula&&stringsInFormula.length){
var clearValue=value.replace(/".+?"|'.+?'/g, '%STR%'),
index=0;
clearValue=clearValue.toUpperCase();
value=clearValue.replace(/%STR%/g, function(match){
var val=match;
if(index < stringsInFormula.length){
val=stringsInFormula[index];
index++;
}
return val;
});
}else{
value=value.toUpperCase();
}
return value;
});
vendor[appName].Base64={
_keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
encode: function(input){
var self=vendor[appName].Base64,
output="",
i=0,
chr1, chr2, chr3, enc1, enc2, enc3, enc4;
input=self._utf8_encode(input);
while (i < input.length){
chr1=input.charCodeAt(i++);
chr2=input.charCodeAt(i++);
chr3=input.charCodeAt(i++);
enc1=chr1 >> 2;
enc2=((chr1 & 3) << 4) | (chr2 >> 4);
enc3=((chr2 & 15) << 2) | (chr3 >> 6);
enc4=chr3 & 63;
if(isNaN(chr2)){
enc3=enc4=64;
}else if(isNaN(chr3)){
enc4=64;
}
output=output +
self._keyStr.charAt(enc1) + self._keyStr.charAt(enc2) +
self._keyStr.charAt(enc3) + self._keyStr.charAt(enc4);
}
return output;
},
_utf8_encode: function(string){
string=string.replace(/\r\n/g, "\n");
var utftext="";
for (var n=0; n < string.length; n++){
var c=string.charCodeAt(n);
if(c < 128){
utftext +=String.fromCharCode(c);
}else if((c > 127)&&(c < 2048)){
utftext +=String.fromCharCode((c >> 6) | 192);
utftext +=String.fromCharCode((c & 63) | 128);
}else{
utftext +=String.fromCharCode((c >> 12) | 224);
utftext +=String.fromCharCode(((c >> 6) & 63) | 128);
utftext +=String.fromCharCode((c & 63) | 128);
}}
return utftext;
}};
vendor[appName].getClassesRegexp=(function(){
return {
color: /color\-([0-9a-f]{6})/,
background: /bg\-([0-9a-f]{6})/,
fontFamily: /ffamily\-([a-z_]+)/i,
fontSize: /fsize\-([0-9]+)/
}});
vendor[appName].setStylesToCell=(function(cell){
var $cell=cell instanceof jQuery ? cell:jQuery(cell),
viewId=$cell.parents('.supsystic-table:first').data('view-id'),
classes=this.getClassesRegexp(),
cellClassNames=$cell.get(0).className,
color=classes.color.exec(cellClassNames),
background=classes.background.exec(cellClassNames),
fontFamily=classes.fontFamily.exec(cellClassNames),
fontSize=classes.fontSize.exec(cellClassNames);
if(null!==color){
$cell.css({
color: '#' + color[1]
});
}
if(null!==background){
$cell.css({
backgroundColor: '#' + background[1]
});
}
if(null!==fontFamily){
var family=fontFamily[1].replace(/_/g, ' '),
familyName=fontFamily[1].replace(/_/g, '+'),
familyString='@import url("//fonts.googleapis.com/css?family=' + familyName + '");';
if(g_stbStandartFontsList &&
toeInArray(family, g_stbStandartFontsList)==-1 &&
g_stbAllFontsList &&
toeInArray(family, g_stbAllFontsList)!=-1
){
var style=this.getFrontendCellStylesElem(viewId);
if(style.text().indexOf(familyString)==-1){
style.text(familyString + '\n' + style.text());
}}
$cell.css({
fontFamily: family
});
}
if(null!==fontSize){
var lineHeight=+fontSize[1] + 6;
$cell.css({
fontSize: fontSize[1] + 'px',
lineHeight: lineHeight + 'px'
});
}});
vendor[appName].getAdminCellStylesElem=(function(){
var $style=jQuery('#supsystic-tables-style');
if(!$style.length){
$style=jQuery('', {
id: 'supsystic-tables-style'
});
jQuery('head').append($style);
}
return $style;
});
vendor[appName].getFrontendCellStylesElem=(function(viewId){
var $style=jQuery('#supsystic-table-' + viewId + '-css');
if(!$style.length){
$style=jQuery('', {
id: 'supsystic-table-' + viewId + '-css'
});
jQuery('head').append($style);
}
return $style;
});
vendor[appName]._fixTableCaption=(function(captionHeight, viewId, counter){
if(counter < 0) return false;
var self=this,
tableViewHtmlId='#supsystic-table-' + viewId,
fixedColumnsWrapper=jQuery(tableViewHtmlId + ' .DTFC_LeftWrapper, ' + tableViewHtmlId + ' .DTFC_RightWrapper');
if(fixedColumnsWrapper.length){
fixedColumnsWrapper.find('caption').css({
display: 'none'
});
fixedColumnsWrapper.css({
top: captionHeight + 'px'
});
}else{
counter--;
setTimeout(function(){
self._fixTableCaption(captionHeight, viewId, counter);
}, 50);
}});
vendor[appName]._getChunksArray=(function(arr, len){
var chunks=[],
i=0,
n=arr.length;
while (i < n){
chunks.push(arr.slice(i, i +=len));
}
return chunks;
});
vendor[appName]._checkOnClickPopups=(function($table){
if(typeof(_ppsBindOnElementClickPopups)!=='undefined'&&$table&&$table.size()){
var $bindedLinks=$table.find('[href*="#ppsShowPopUp_"].ppsClickBinded');
if($bindedLinks&&$bindedLinks.size()){
$bindedLinks.removeClass('ppsClickBinded').unbind('click');
}
_ppsBindOnElementClickPopups();
}});
vendor[appName].setCellAttributes=function(cells){
var colspan, rowspan;
for (var i=0; i < cells.length; i++){
if(cells[i].getAttribute('data-hide')){
cells[i].style.display='none';
}
if(colspan=cells[i].getAttribute('data-colspan')){
if(colspan > 1){
cells[i].setAttribute('colspan', colspan);
jQuery(cells[i]).attr('colspan', colspan);
}}
if(rowspan=cells[i].getAttribute('data-rowspan')){
if(rowspan > 1){
cells[i].setAttribute('rowspan', rowspan);
}}
}};}}(window.supsystic=window.supsystic||{}, window.jQuery, window));
function classesRegexp(){
return window.supsystic.Tables.getClassesRegexp();
}
function getAdminCellStylesElem(){
return window.supsystic.Tables.getAdminCellStylesElem();
}
function toeInArray(needle, haystack){
if(typeof(haystack)=='object'){
for (var k in haystack){
if(haystack[k]==needle)
return k;
}}else if(typeof(haystack)=='array'){
return jQuery.inArray(needle, haystack);
}
return -1;
}
(function($){
jQuery.fn.isVerticallyScrollable=function(){
if(this.scrollTop()){
return true;
}else{
this.scrollTop(1);
if(this.scrollTop()){
this.scrollTop(0);
return true;
}}
return false;
};
jQuery.fn.isHorizontallyScrollable=function(){
if(this.scrollLeft()){
return true;
}else{
this.scrollLeft(1);
if(this.scrollLeft()){
this.scrollLeft(0);
return true;
}}
return false;
};
jQuery.extend(jQuery.expr.pseudos||jQuery.expr[":"], {
"vertically-scrollable": function(a, i, m){
return jQuery(a).isVerticallyScrollable();
},
"horizontally-scrollable": function(a, i, m){
return jQuery(a).isHorizontallyScrollable();
}});
jQuery.fn.removeStyle=function(style){
var search=new RegExp(style + '[^;]+;?', 'g');
return this.each(function(){
jQuery(this).attr('style', function(i, style){
return style&&style.replace(search, '');
});
});
};
if(!Array.from){
Array.from=(function(){
var toStr=Object.prototype.toString;
var isCallable=function(fn){
return typeof fn==='function'||toStr.call(fn)==='[object Function]';
};
var toInteger=function(value){
var number=Number(value);
if(isNaN(number)){
return 0;
}
if(number===0||!isFinite(number)){
return number;
}
return (number > 0 ? 1:-1) * Math.floor(Math.abs(number));
};
var maxSafeInteger=Math.pow(2, 53) - 1;
var toLength=function(value){
var len=toInteger(value);
return Math.min(Math.max(len, 0), maxSafeInteger);
};
return function from(arrayLike ){
var C=this;
var items=Object(arrayLike);
if(arrayLike==null){
throw new TypeError('Array.from requires an array-like object - not null or undefined');
}
var mapFn=arguments.length > 1 ? arguments[1]:void undefined;
var T;
if(typeof mapFn!=='undefined'){
if(!isCallable(mapFn)){
throw new TypeError('Array.from: when provided, the second argument must be a function');
}
if(arguments.length > 2){
T=arguments[2];
}}
var len=toLength(items.length);
var A=isCallable(C) ? Object(new C(len)):new Array(len);
var k=0;
var kValue;
while (k < len){
kValue=items[k];
if(mapFn){
A[k]=typeof T==='undefined' ? mapFn(kValue, k):mapFn.call(T, kValue, k);
}else{
A[k]=kValue;
}
k +=1;
}
A.length=len;
return A;
};}());
}}(jQuery));
_u=typeof _=='function'&&_.noConflict();
;(function(){
var undefined;
var arrayPool=[],
objectPool=[];
var idCounter=0;
var keyPrefix=+new Date + '';
var largeArraySize=75;
var maxPoolSize=40;
var whitespace=(
' \t\x0B\f\xA0\ufeff' +
'\n\r\u2028\u2029' +
'\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000'
);
var reEmptyStringLeading=/\b__p \+='';/g,
reEmptyStringMiddle=/\b(__p \+=) '' \+/g,
reEmptyStringTrailing=/(__e\(.*?\)|\b__t\)) \+\n'';/g;
var reEsTemplate=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
var reFlags=/\w*$/;
var reFuncName=/^\s*function[ \n\r\t]+\w/;
var reInterpolate=/<%=([\s\S]+?)%>/g;
var reLeadingSpacesAndZeros=RegExp('^[' + whitespace + ']*0+(?=.$)');
var reNoMatch=/($^)/;
var reThis=/\bthis\b/;
var reUnescapedString=/['\n\r\t\u2028\u2029\\]/g;
var contextProps=[
'Array', 'Boolean', 'Date', 'Function', 'Math', 'Number', 'Object',
'RegExp', 'String', '_', 'attachEvent', 'clearTimeout', 'isFinite', 'isNaN',
'parseInt', 'setTimeout'
];
var templateCounter=0;
var argsClass='[object Arguments]',
arrayClass='[object Array]',
boolClass='[object Boolean]',
dateClass='[object Date]',
funcClass='[object Function]',
numberClass='[object Number]',
objectClass='[object Object]',
regexpClass='[object RegExp]',
stringClass='[object String]';
var cloneableClasses={};
cloneableClasses[funcClass]=false;
cloneableClasses[argsClass]=cloneableClasses[arrayClass] =
cloneableClasses[boolClass]=cloneableClasses[dateClass] =
cloneableClasses[numberClass]=cloneableClasses[objectClass] =
cloneableClasses[regexpClass]=cloneableClasses[stringClass]=true;
var debounceOptions={
'leading': false,
'maxWait': 0,
'trailing': false
};
var descriptor={
'configurable': false,
'enumerable': false,
'value': null,
'writable': false
};
var objectTypes={
'boolean': false,
'function': true,
'object': true,
'number': false,
'string': false,
'undefined': false
};
var stringEscapes={
'\\': '\\',
"'": "'",
'\n': 'n',
'\r': 'r',
'\t': 't',
'\u2028': 'u2028',
'\u2029': 'u2029'
};
var root=(objectTypes[typeof window]&&window)||this;
var freeExports=objectTypes[typeof exports]&&exports&&!exports.nodeType&&exports;
var freeModule=objectTypes[typeof module]&&module&&!module.nodeType&&module;
var moduleExports=freeModule&&freeModule.exports===freeExports&&freeExports;
var freeGlobal=objectTypes[typeof global]&&global;
if(freeGlobal&&(freeGlobal.global===freeGlobal||freeGlobal.window===freeGlobal)){
root=freeGlobal;
}
function baseIndexOf(array, value, fromIndex){
var index=(fromIndex||0) - 1,
length=array ? array.length:0;
while (++index < length){
if(array[index]===value){
return index;
}}
return -1;
}
function cacheIndexOf(cache, value){
var type=typeof value;
cache=cache.cache;
if(type=='boolean'||value==null){
return cache[value] ? 0:-1;
}
if(type!='number'&&type!='string'){
type='object';
}
var key=type=='number' ? value:keyPrefix + value;
cache=(cache=cache[type])&&cache[key];
return type=='object'
? (cache&&baseIndexOf(cache, value) > -1 ? 0:-1)
: (cache ? 0:-1);
}
function cachePush(value){
var cache=this.cache,
type=typeof value;
if(type=='boolean'||value==null){
cache[value]=true;
}else{
if(type!='number'&&type!='string'){
type='object';
}
var key=type=='number' ? value:keyPrefix + value,
typeCache=cache[type]||(cache[type]={});
if(type=='object'){
(typeCache[key]||(typeCache[key]=[])).push(value);
}else{
typeCache[key]=true;
}}
}
function charAtCallback(value){
return value.charCodeAt(0);
}
function compareAscending(a, b){
var ac=a.criteria,
bc=b.criteria,
index=-1,
length=ac.length;
while (++index < length){
var value=ac[index],
other=bc[index];
if(value!==other){
if(value > other||typeof value=='undefined'){
return 1;
}
if(value < other||typeof other=='undefined'){
return -1;
}}
}
return a.index - b.index;
}
function createCache(array){
var index=-1,
length=array.length,
first=array[0],
mid=array[(length / 2) | 0],
last=array[length - 1];
if(first&&typeof first=='object' &&
mid&&typeof mid=='object'&&last&&typeof last=='object'){
return false;
}
var cache=getObject();
cache['false']=cache['null']=cache['true']=cache['undefined']=false;
var result=getObject();
result.array=array;
result.cache=cache;
result.push=cachePush;
while (++index < length){
result.push(array[index]);
}
return result;
}
function escapeStringChar(match){
return '\\' + stringEscapes[match];
}
function getArray(){
return arrayPool.pop()||[];
}
function getObject(){
return objectPool.pop()||{
'array': null,
'cache': null,
'criteria': null,
'false': false,
'index': 0,
'null': false,
'number': null,
'object': null,
'push': null,
'string': null,
'true': false,
'undefined': false,
'value': null
};}
function releaseArray(array){
array.length=0;
if(arrayPool.length < maxPoolSize){
arrayPool.push(array);
}}
function releaseObject(object){
var cache=object.cache;
if(cache){
releaseObject(cache);
}
object.array=object.cache=object.criteria=object.object=object.number=object.string=object.value=null;
if(objectPool.length < maxPoolSize){
objectPool.push(object);
}}
function slice(array, start, end){
start||(start=0);
if(typeof end=='undefined'){
end=array ? array.length:0;
}
var index=-1,
length=end - start||0,
result=Array(length < 0 ? 0:length);
while (++index < length){
result[index]=array[start + index];
}
return result;
}
function runInContext(context){
context=context ? _.defaults(root.Object(), context, _.pick(root, contextProps)):root;
var Array=context.Array,
Boolean=context.Boolean,
Date=context.Date,
Function=context.Function,
Math=context.Math,
Number=context.Number,
Object=context.Object,
RegExp=context.RegExp,
String=context.String,
TypeError=context.TypeError;
var arrayRef=[];
var objectProto=Object.prototype;
var oldDash=context._;
var toString=objectProto.toString;
var reNative=RegExp('^' +
String(toString)
.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
.replace(/toString| for [^\]]+/g, '.*?') + '$'
);
var ceil=Math.ceil,
clearTimeout=context.clearTimeout,
floor=Math.floor,
fnToString=Function.prototype.toString,
getPrototypeOf=isNative(getPrototypeOf=Object.getPrototypeOf)&&getPrototypeOf,
hasOwnProperty=objectProto.hasOwnProperty,
push=arrayRef.push,
setTimeout=context.setTimeout,
splice=arrayRef.splice,
unshift=arrayRef.unshift;
var defineProperty=(function(){
try {
var o={},
func=isNative(func=Object.defineProperty)&&func,
result=func(o, o, o)&&func;
} catch(e){ }
return result;
}());
var nativeCreate=isNative(nativeCreate=Object.create)&&nativeCreate,
nativeIsArray=isNative(nativeIsArray=Array.isArray)&&nativeIsArray,
nativeIsFinite=context.isFinite,
nativeIsNaN=context.isNaN,
nativeKeys=isNative(nativeKeys=Object.keys)&&nativeKeys,
nativeMax=Math.max,
nativeMin=Math.min,
nativeParseInt=context.parseInt,
nativeRandom=Math.random;
var ctorByClass={};
ctorByClass[arrayClass]=Array;
ctorByClass[boolClass]=Boolean;
ctorByClass[dateClass]=Date;
ctorByClass[funcClass]=Function;
ctorByClass[objectClass]=Object;
ctorByClass[numberClass]=Number;
ctorByClass[regexpClass]=RegExp;
ctorByClass[stringClass]=String;
/**
* Creates a `lodash` object which wraps the given value to enable intuitive
* method chaining.
*
* In addition to Lo-Dash methods, wrappers also have the following `Array` methods:
* `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`, `splice`,
* and `unshift`
*
* Chaining is supported in custom builds as long as the `value` method is
* implicitly or explicitly included in the build.
*
* The chainable wrapper functions are:
* `after`, `assign`, `bind`, `bindAll`, `bindKey`, `chain`, `compact`,
* `compose`, `concat`, `countBy`, `create`, `createCallback`, `curry`,
* `debounce`, `defaults`, `defer`, `delay`, `difference`, `filter`, `flatten`,
* `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`,
* `functions`, `groupBy`, `indexBy`, `initial`, `intersection`, `invert`,
* `invoke`, `keys`, `map`, `max`, `memoize`, `merge`, `min`, `object`, `omit`,
* `once`, `pairs`, `partial`, `partialRight`, `pick`, `pluck`, `pull`, `push`,
* `range`, `reject`, `remove`, `rest`, `reverse`, `shuffle`, `slice`, `sort`,
* `sortBy`, `splice`, `tap`, `throttle`, `times`, `toArray`, `transform`,
* `union`, `uniq`, `unshift`, `unzip`, `values`, `where`, `without`, `wrap`,
* and `zip`
*
* The non-chainable wrapper functions are:
* `clone`, `cloneDeep`, `contains`, `escape`, `every`, `find`, `findIndex`,
* `findKey`, `findLast`, `findLastIndex`, `findLastKey`, `has`, `identity`,
* `indexOf`, `isArguments`, `isArray`, `isBoolean`, `isDate`, `isElement`,
* `isEmpty`, `isEqual`, `isFinite`, `isFunction`, `isNaN`, `isNull`, `isNumber`,
* `isObject`, `isPlainObject`, `isRegExp`, `isString`, `isUndefined`, `join`,
* `lastIndexOf`, `mixin`, `noConflict`, `parseInt`, `pop`, `random`, `reduce`,
* `reduceRight`, `result`, `shift`, `size`, `some`, `sortedIndex`, `runInContext`,
* `template`, `unescape`, `uniqueId`, and `value`
*
* The wrapper functions `first` and `last` return wrapped values when `n` is
* provided, otherwise they return unwrapped values.
*
* Explicit chaining can be enabled by using the `_.chain` method.
*
* @name _
* @constructor
* @category Chaining
* @param {*} value The value to wrap in a `lodash` instance.
* @returns {Object} Returns a `lodash` instance.
* @example
*
* var wrapped=_([1, 2, 3]);
*
*
* wrapped.reduce(function(sum, num){
* return sum + num;
* });
*
*
*
* var squares=wrapped.map(function(num){
* return num * num;
* });
*
* _.isArray(squares);
*
*
* _.isArray(squares.value());
*
*/
function lodash(value){
return (value&&typeof value=='object'&&!isArray(value)&&hasOwnProperty.call(value, '__wrapped__'))
? value
: new lodashWrapper(value);
}
function lodashWrapper(value, chainAll){
this.__chain__ = !!chainAll;
this.__wrapped__=value;
}
lodashWrapper.prototype=lodash.prototype;
var support=lodash.support={};
support.funcDecomp = !isNative(context.WinRTError)&&reThis.test(runInContext);
support.funcNames=typeof Function.name=='string';
lodash.templateSettings={
'escape': /<%-([\s\S]+?)%>/g,
'evaluate': /<%([\s\S]+?)%>/g,
'interpolate': reInterpolate,
'variable': '',
'imports': {
'_': lodash
}};
function baseBind(bindData){
var func=bindData[0],
partialArgs=bindData[2],
thisArg=bindData[4];
function bound(){
if(partialArgs){
var args=slice(partialArgs);
push.apply(args, arguments);
}
if(this instanceof bound){
var thisBinding=baseCreate(func.prototype),
result=func.apply(thisBinding, args||arguments);
return isObject(result) ? result:thisBinding;
}
return func.apply(thisArg, args||arguments);
}
setBindData(bound, bindData);
return bound;
}
function baseClone(value, isDeep, callback, stackA, stackB){
if(callback){
var result=callback(value);
if(typeof result!='undefined'){
return result;
}}
var isObj=isObject(value);
if(isObj){
var className=toString.call(value);
if(!cloneableClasses[className]){
return value;
}
var ctor=ctorByClass[className];
switch (className){
case boolClass:
case dateClass:
return new ctor(+value);
case numberClass:
case stringClass:
return new ctor(value);
case regexpClass:
result=ctor(value.source, reFlags.exec(value));
result.lastIndex=value.lastIndex;
return result;
}}else{
return value;
}
var isArr=isArray(value);
if(isDeep){
var initedStack = !stackA;
stackA||(stackA=getArray());
stackB||(stackB=getArray());
var length=stackA.length;
while (length--){
if(stackA[length]==value){
return stackB[length];
}}
result=isArr ? ctor(value.length):{};}else{
result=isArr ? slice(value):assign({}, value);
}
if(isArr){
if(hasOwnProperty.call(value, 'index')){
result.index=value.index;
}
if(hasOwnProperty.call(value, 'input')){
result.input=value.input;
}}
if(!isDeep){
return result;
}
stackA.push(value);
stackB.push(result);
(isArr ? forEach:forOwn)(value, function(objValue, key){
result[key]=baseClone(objValue, isDeep, callback, stackA, stackB);
});
if(initedStack){
releaseArray(stackA);
releaseArray(stackB);
}
return result;
}
function baseCreate(prototype, properties){
return isObject(prototype) ? nativeCreate(prototype):{};}
if(!nativeCreate){
baseCreate=(function(){
function Object(){}
return function(prototype){
if(isObject(prototype)){
Object.prototype=prototype;
var result=new Object;
Object.prototype=null;
}
return result||context.Object();
};}());
}
function baseCreateCallback(func, thisArg, argCount){
if(typeof func!='function'){
return identity;
}
if(typeof thisArg=='undefined'||!('prototype' in func)){
return func;
}
var bindData=func.__bindData__;
if(typeof bindData=='undefined'){
if(support.funcNames){
bindData = !func.name;
}
bindData=bindData||!support.funcDecomp;
if(!bindData){
var source=fnToString.call(func);
if(!support.funcNames){
bindData = !reFuncName.test(source);
}
if(!bindData){
bindData=reThis.test(source);
setBindData(func, bindData);
}}
}
if(bindData===false||(bindData!==true&&bindData[1] & 1)){
return func;
}
switch (argCount){
case 1: return function(value){
return func.call(thisArg, value);
};
case 2: return function(a, b){
return func.call(thisArg, a, b);
};
case 3: return function(value, index, collection){
return func.call(thisArg, value, index, collection);
};
case 4: return function(accumulator, value, index, collection){
return func.call(thisArg, accumulator, value, index, collection);
};}
return bind(func, thisArg);
}
function baseCreateWrapper(bindData){
var func=bindData[0],
bitmask=bindData[1],
partialArgs=bindData[2],
partialRightArgs=bindData[3],
thisArg=bindData[4],
arity=bindData[5];
var isBind=bitmask & 1,
isBindKey=bitmask & 2,
isCurry=bitmask & 4,
isCurryBound=bitmask & 8,
key=func;
function bound(){
var thisBinding=isBind ? thisArg:this;
if(partialArgs){
var args=slice(partialArgs);
push.apply(args, arguments);
}
if(partialRightArgs||isCurry){
args||(args=slice(arguments));
if(partialRightArgs){
push.apply(args, partialRightArgs);
}
if(isCurry&&args.length < arity){
bitmask |=16 & ~32;
return baseCreateWrapper([func, (isCurryBound ? bitmask:bitmask & ~3), args, null, thisArg, arity]);
}}
args||(args=arguments);
if(isBindKey){
func=thisBinding[key];
}
if(this instanceof bound){
thisBinding=baseCreate(func.prototype);
var result=func.apply(thisBinding, args);
return isObject(result) ? result:thisBinding;
}
return func.apply(thisBinding, args);
}
setBindData(bound, bindData);
return bound;
}
function baseDifference(array, values){
var index=-1,
indexOf=getIndexOf(),
length=array ? array.length:0,
isLarge=length >=largeArraySize&&indexOf===baseIndexOf,
result=[];
if(isLarge){
var cache=createCache(values);
if(cache){
indexOf=cacheIndexOf;
values=cache;
}else{
isLarge=false;
}}
while (++index < length){
var value=array[index];
if(indexOf(values, value) < 0){
result.push(value);
}}
if(isLarge){
releaseObject(values);
}
return result;
}
function baseFlatten(array, isShallow, isStrict, fromIndex){
var index=(fromIndex||0) - 1,
length=array ? array.length:0,
result=[];
while (++index < length){
var value=array[index];
if(value&&typeof value=='object'&&typeof value.length=='number'
&& (isArray(value)||isArguments(value))){
if(!isShallow){
value=baseFlatten(value, isShallow, isStrict);
}
var valIndex=-1,
valLength=value.length,
resIndex=result.length;
result.length +=valLength;
while (++valIndex < valLength){
result[resIndex++]=value[valIndex];
}}else if(!isStrict){
result.push(value);
}}
return result;
}
function baseIsEqual(a, b, callback, isWhere, stackA, stackB){
if(callback){
var result=callback(a, b);
if(typeof result!='undefined'){
return !!result;
}}
if(a===b){
return a!==0||(1 / a==1 / b);
}
var type=typeof a,
otherType=typeof b;
if(a===a &&
!(a&&objectTypes[type]) &&
!(b&&objectTypes[otherType])){
return false;
}
if(a==null||b==null){
return a===b;
}
var className=toString.call(a),
otherClass=toString.call(b);
if(className==argsClass){
className=objectClass;
}
if(otherClass==argsClass){
otherClass=objectClass;
}
if(className!=otherClass){
return false;
}
switch (className){
case boolClass:
case dateClass:
return +a==+b;
case numberClass:
return (a!=+a)
? b!=+b
: (a==0 ? (1 / a==1 / b):a==+b);
case regexpClass:
case stringClass:
return a==String(b);
}
var isArr=className==arrayClass;
if(!isArr){
var aWrapped=hasOwnProperty.call(a, '__wrapped__'),
bWrapped=hasOwnProperty.call(b, '__wrapped__');
if(aWrapped||bWrapped){
return baseIsEqual(aWrapped ? a.__wrapped__:a, bWrapped ? b.__wrapped__:b, callback, isWhere, stackA, stackB);
}
if(className!=objectClass){
return false;
}
var ctorA=a.constructor,
ctorB=b.constructor;
if(ctorA!=ctorB &&
!(isFunction(ctorA)&&ctorA instanceof ctorA&&isFunction(ctorB)&&ctorB instanceof ctorB) &&
('constructor' in a&&'constructor' in b)
){
return false;
}}
var initedStack = !stackA;
stackA||(stackA=getArray());
stackB||(stackB=getArray());
var length=stackA.length;
while (length--){
if(stackA[length]==a){
return stackB[length]==b;
}}
var size=0;
result=true;
stackA.push(a);
stackB.push(b);
if(isArr){
length=a.length;
size=b.length;
result=size==length;
if(result||isWhere){
while (size--){
var index=length,
value=b[size];
if(isWhere){
while (index--){
if((result=baseIsEqual(a[index], value, callback, isWhere, stackA, stackB))){
break;
}}
}else if(!(result=baseIsEqual(a[size], value, callback, isWhere, stackA, stackB))){
break;
}}
}}else{
forIn(b, function(value, key, b){
if(hasOwnProperty.call(b, key)){
size++;
return (result=hasOwnProperty.call(a, key)&&baseIsEqual(a[key], value, callback, isWhere, stackA, stackB));
}});
if(result&&!isWhere){
forIn(a, function(value, key, a){
if(hasOwnProperty.call(a, key)){
return (result=--size > -1);
}});
}}
stackA.pop();
stackB.pop();
if(initedStack){
releaseArray(stackA);
releaseArray(stackB);
}
return result;
}
function baseMerge(object, source, callback, stackA, stackB){
(isArray(source) ? forEach:forOwn)(source, function(source, key){
var found,
isArr,
result=source,
value=object[key];
if(source&&((isArr=isArray(source))||isPlainObject(source))){
var stackLength=stackA.length;
while (stackLength--){
if((found=stackA[stackLength]==source)){
value=stackB[stackLength];
break;
}}
if(!found){
var isShallow;
if(callback){
result=callback(value, source);
if((isShallow=typeof result!='undefined')){
value=result;
}}
if(!isShallow){
value=isArr
? (isArray(value) ? value:[])
: (isPlainObject(value) ? value:{});
}
stackA.push(source);
stackB.push(value);
if(!isShallow){
baseMerge(value, source, callback, stackA, stackB);
}}
}else{
if(callback){
result=callback(value, source);
if(typeof result=='undefined'){
result=source;
}}
if(typeof result!='undefined'){
value=result;
}}
object[key]=value;
});
}
function baseRandom(min, max){
return min + floor(nativeRandom() * (max - min + 1));
}
function baseUniq(array, isSorted, callback){
var index=-1,
indexOf=getIndexOf(),
length=array ? array.length:0,
result=[];
var isLarge = !isSorted&&length >=largeArraySize&&indexOf===baseIndexOf,
seen=(callback||isLarge) ? getArray():result;
if(isLarge){
var cache=createCache(seen);
indexOf=cacheIndexOf;
seen=cache;
}
while (++index < length){
var value=array[index],
computed=callback ? callback(value, index, array):value;
if(isSorted
? !index||seen[seen.length - 1]!==computed
: indexOf(seen, computed) < 0
){
if(callback||isLarge){
seen.push(computed);
}
result.push(value);
}}
if(isLarge){
releaseArray(seen.array);
releaseObject(seen);
}else if(callback){
releaseArray(seen);
}
return result;
}
function createAggregator(setter){
return function(collection, callback, thisArg){
var result={};
callback=lodash.createCallback(callback, thisArg, 3);
var index=-1,
length=collection ? collection.length:0;
if(typeof length=='number'){
while (++index < length){
var value=collection[index];
setter(result, value, callback(value, index, collection), collection);
}}else{
forOwn(collection, function(value, key, collection){
setter(result, value, callback(value, key, collection), collection);
});
}
return result;
};}
function createWrapper(func, bitmask, partialArgs, partialRightArgs, thisArg, arity){
var isBind=bitmask & 1,
isBindKey=bitmask & 2,
isCurry=bitmask & 4,
isCurryBound=bitmask & 8,
isPartial=bitmask & 16,
isPartialRight=bitmask & 32;
if(!isBindKey&&!isFunction(func)){
throw new TypeError;
}
if(isPartial&&!partialArgs.length){
bitmask &=~16;
isPartial=partialArgs=false;
}
if(isPartialRight&&!partialRightArgs.length){
bitmask &=~32;
isPartialRight=partialRightArgs=false;
}
var bindData=func&&func.__bindData__;
if(bindData&&bindData!==true){
bindData=slice(bindData);
if(bindData[2]){
bindData[2]=slice(bindData[2]);
}
if(bindData[3]){
bindData[3]=slice(bindData[3]);
}
if(isBind&&!(bindData[1] & 1)){
bindData[4]=thisArg;
}
if(!isBind&&bindData[1] & 1){
bitmask |=8;
}
if(isCurry&&!(bindData[1] & 4)){
bindData[5]=arity;
}
if(isPartial){
push.apply(bindData[2]||(bindData[2]=[]), partialArgs);
}
if(isPartialRight){
unshift.apply(bindData[3]||(bindData[3]=[]), partialRightArgs);
}
bindData[1] |=bitmask;
return createWrapper.apply(null, bindData);
}
var creater=(bitmask==1||bitmask===17) ? baseBind:baseCreateWrapper;
return creater([func, bitmask, partialArgs, partialRightArgs, thisArg, arity]);
}
function escapeHtmlChar(match){
return htmlEscapes[match];
}
function getIndexOf(){
var result=(result=lodash.indexOf)===indexOf ? baseIndexOf:result;
return result;
}
function isNative(value){
return typeof value=='function'&&reNative.test(value);
}
var setBindData = !defineProperty ? noop:function(func, value){
descriptor.value=value;
defineProperty(func, '__bindData__', descriptor);
};
function shimIsPlainObject(value){
var ctor,
result;
if(!(value&&toString.call(value)==objectClass) ||
(ctor=value.constructor, isFunction(ctor)&&!(ctor instanceof ctor))){
return false;
}
forIn(value, function(value, key){
result=key;
});
return typeof result=='undefined'||hasOwnProperty.call(value, result);
}
function unescapeHtmlChar(match){
return htmlUnescapes[match];
}
/**
* Checks if `value` is an `arguments` object.
*
* @static
* @memberOf _
* @category Objects
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if the `value` is an `arguments` object, else `false`.
* @example
*
* (function(){ return _.isArguments(arguments); })(1, 2, 3);
*
*
* _.isArguments([1, 2, 3]);
*
*/
function isArguments(value){
return value&&typeof value=='object'&&typeof value.length=='number' &&
toString.call(value)==argsClass||false;
}
/**
* Checks if `value` is an array.
*
* @static
* @memberOf _
* @type Function
* @category Objects
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if the `value` is an array, else `false`.
* @example
*
* (function(){ return _.isArray(arguments); })();
*
*
* _.isArray([1, 2, 3]);
*
*/
var isArray=nativeIsArray||function(value){
return value&&typeof value=='object'&&typeof value.length=='number' &&
toString.call(value)==arrayClass||false;
};
var shimKeys=function(object){
var index, iterable=object, result=[];
if(!iterable) return result;
if(!(objectTypes[typeof object])) return result;
for (index in iterable){
if(hasOwnProperty.call(iterable, index)){
result.push(index);
}}
return result
};
var keys = !nativeKeys ? shimKeys:function(object){
if(!isObject(object)){
return [];
}
return nativeKeys(object);
};
var htmlEscapes={
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": '''
};
var htmlUnescapes=invert(htmlEscapes);
var reEscapedHtml=RegExp('(' + keys(htmlUnescapes).join('|') + ')', 'g'),
reUnescapedHtml=RegExp('[' + keys(htmlEscapes).join('') + ']', 'g');
/**
* Assigns own enumerable properties of source object(s) to the destination
* object. Subsequent sources will overwrite property assignments of previous
* sources. If a callback is provided it will be executed to produce the
* assigned values. The callback is bound to `thisArg` and invoked with two
* arguments; (objectValue, sourceValue).
*
* @static
* @memberOf _
* @type Function
* @alias extend
* @category Objects
* @param {Object} object The destination object.
* @param {...Object} [source] The source objects.
* @param {Function} [callback] The function to customize assigning values.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Object} Returns the destination object.
* @example
*
* _.assign({ 'name': 'fred' }, { 'employer': 'slate' });
*
*
* var defaults=_.partialRight(_.assign, function(a, b){
* return typeof a=='undefined' ? b:a;
* });
*
* var object={ 'name': 'barney' };
* defaults(object, { 'name': 'fred', 'employer': 'slate' });
*
*/
var assign=function(object, source, guard){
var index, iterable=object, result=iterable;
if(!iterable) return result;
var args=arguments,
argsIndex=0,
argsLength=typeof guard=='number' ? 2:args.length;
if(argsLength > 3&&typeof args[argsLength - 2]=='function'){
var callback=baseCreateCallback(args[--argsLength - 1], args[argsLength--], 2);
}else if(argsLength > 2&&typeof args[argsLength - 1]=='function'){
callback=args[--argsLength];
}
while (++argsIndex < argsLength){
iterable=args[argsIndex];
if(iterable&&objectTypes[typeof iterable]){
var ownIndex=-1,
ownProps=objectTypes[typeof iterable]&&keys(iterable),
length=ownProps ? ownProps.length:0;
while (++ownIndex < length){
index=ownProps[ownIndex];
result[index]=callback ? callback(result[index], iterable[index]):iterable[index];
}}
}
return result
};
/**
* Creates a clone of `value`. If `isDeep` is `true` nested objects will also
* be cloned, otherwise they will be assigned by reference. If a callback
* is provided it will be executed to produce the cloned values. If the
* callback returns `undefined` cloning will be handled by the method instead.
* The callback is bound to `thisArg` and invoked with one argument; (value).
*
* @static
* @memberOf _
* @category Objects
* @param {*} value The value to clone.
* @param {boolean} [isDeep=false] Specify a deep clone.
* @param {Function} [callback] The function to customize cloning values.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {*} Returns the cloned value.
* @example
*
* var characters=[
* { 'name': 'barney', 'age': 36 },
* { 'name': 'fred', 'age': 40 }
* ];
*
* var shallow=_.clone(characters);
* shallow[0]===characters[0];
*
*
* var deep=_.clone(characters, true);
* deep[0]===characters[0];
*
*
* _.mixin({
* 'clone': _.partialRight(_.clone, function(value){
* return _.isElement(value) ? value.cloneNode(false):undefined;
* })
* });
*
* var clone=_.clone(document.body);
* clone.childNodes.length;
*
*/
function clone(value, isDeep, callback, thisArg){
if(typeof isDeep!='boolean'&&isDeep!=null){
thisArg=callback;
callback=isDeep;
isDeep=false;
}
return baseClone(value, isDeep, typeof callback=='function'&&baseCreateCallback(callback, thisArg, 1));
}
/**
* Creates a deep clone of `value`. If a callback is provided it will be
* executed to produce the cloned values. If the callback returns `undefined`
* cloning will be handled by the method instead. The callback is bound to
* `thisArg` and invoked with one argument; (value).
*
* Note: This method is loosely based on the structured clone algorithm. Functions
* and DOM nodes are **not** cloned. The enumerable properties of `arguments` objects and
* objects created by constructors other than `Object` are cloned to plain `Object` objects.
* See http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm.
*
* @static
* @memberOf _
* @category Objects
* @param {*} value The value to deep clone.
* @param {Function} [callback] The function to customize cloning values.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {*} Returns the deep cloned value.
* @example
*
* var characters=[
* { 'name': 'barney', 'age': 36 },
* { 'name': 'fred', 'age': 40 }
* ];
*
* var deep=_.cloneDeep(characters);
* deep[0]===characters[0];
*
*
* var view={
* 'label': 'docs',
* 'node': element
* };
*
* var clone=_.cloneDeep(view, function(value){
* return _.isElement(value) ? value.cloneNode(true):undefined;
* });
*
* clone.node==view.node;
*
*/
function cloneDeep(value, callback, thisArg){
return baseClone(value, true, typeof callback=='function'&&baseCreateCallback(callback, thisArg, 1));
}
function create(prototype, properties){
var result=baseCreate(prototype);
return properties ? assign(result, properties):result;
}
var defaults=function(object, source, guard){
var index, iterable=object, result=iterable;
if(!iterable) return result;
var args=arguments,
argsIndex=0,
argsLength=typeof guard=='number' ? 2:args.length;
while (++argsIndex < argsLength){
iterable=args[argsIndex];
if(iterable&&objectTypes[typeof iterable]){
var ownIndex=-1,
ownProps=objectTypes[typeof iterable]&&keys(iterable),
length=ownProps ? ownProps.length:0;
while (++ownIndex < length){
index=ownProps[ownIndex];
if(typeof result[index]=='undefined') result[index]=iterable[index];
}}
}
return result
};
/**
* This method is like `_.findIndex` except that it returns the key of the
* first element that passes the callback check, instead of the element itself.
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @category Objects
* @param {Object} object The object to search.
* @param {Function|Object|string} [callback=identity] The function called per
* iteration. If a property name or object is provided it will be used to
* create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {string|undefined} Returns the key of the found element, else `undefined`.
* @example
*
* var characters={
* 'barney': { 'age': 36, 'blocked': false },
* 'fred': { 'age': 40, 'blocked': true },
* 'pebbles': { 'age': 1, 'blocked': false }
* };
*
* _.findKey(characters, function(chr){
* return chr.age < 40;
* });
*
*
*
* _.findKey(characters, { 'age': 1 });
*
*
*
* _.findKey(characters, 'blocked');
*
*/
function findKey(object, callback, thisArg){
var result;
callback=lodash.createCallback(callback, thisArg, 3);
forOwn(object, function(value, key, object){
if(callback(value, key, object)){
result=key;
return false;
}});
return result;
}
/**
* This method is like `_.findKey` except that it iterates over elements
* of a `collection` in the opposite order.
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @category Objects
* @param {Object} object The object to search.
* @param {Function|Object|string} [callback=identity] The function called per
* iteration. If a property name or object is provided it will be used to
* create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {string|undefined} Returns the key of the found element, else `undefined`.
* @example
*
* var characters={
* 'barney': { 'age': 36, 'blocked': true },
* 'fred': { 'age': 40, 'blocked': false },
* 'pebbles': { 'age': 1, 'blocked': true }
* };
*
* _.findLastKey(characters, function(chr){
* return chr.age < 40;
* });
*
*
*
* _.findLastKey(characters, { 'age': 40 });
*
*
*
* _.findLastKey(characters, 'blocked');
*
*/
function findLastKey(object, callback, thisArg){
var result;
callback=lodash.createCallback(callback, thisArg, 3);
forOwnRight(object, function(value, key, object){
if(callback(value, key, object)){
result=key;
return false;
}});
return result;
}
/**
* Iterates over own and inherited enumerable properties of an object,
* executing the callback for each property. The callback is bound to `thisArg`
* and invoked with three arguments; (value, key, object). Callbacks may exit
* iteration early by explicitly returning `false`.
*
* @static
* @memberOf _
* @type Function
* @category Objects
* @param {Object} object The object to iterate over.
* @param {Function} [callback=identity] The function called per iteration.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Object} Returns `object`.
* @example
*
* function Shape(){
* this.x=0;
* this.y=0;
* }
*
* Shape.prototype.move=function(x, y){
* this.x +=x;
* this.y +=y;
* };
*
* _.forIn(new Shape, function(value, key){
* console.log(key);
* });
*
*/
var forIn=function(collection, callback, thisArg){
var index, iterable=collection, result=iterable;
if(!iterable) return result;
if(!objectTypes[typeof iterable]) return result;
callback=callback&&typeof thisArg=='undefined' ? callback:baseCreateCallback(callback, thisArg, 3);
for (index in iterable){
if(callback(iterable[index], index, collection)===false) return result;
}
return result
};
/**
* This method is like `_.forIn` except that it iterates over elements
* of a `collection` in the opposite order.
*
* @static
* @memberOf _
* @category Objects
* @param {Object} object The object to iterate over.
* @param {Function} [callback=identity] The function called per iteration.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Object} Returns `object`.
* @example
*
* function Shape(){
* this.x=0;
* this.y=0;
* }
*
* Shape.prototype.move=function(x, y){
* this.x +=x;
* this.y +=y;
* };
*
* _.forInRight(new Shape, function(value, key){
* console.log(key);
* });
*
*/
function forInRight(object, callback, thisArg){
var pairs=[];
forIn(object, function(value, key){
pairs.push(key, value);
});
var length=pairs.length;
callback=baseCreateCallback(callback, thisArg, 3);
while (length--){
if(callback(pairs[length--], pairs[length], object)===false){
break;
}}
return object;
}
/**
* Iterates over own enumerable properties of an object, executing the callback
* for each property. The callback is bound to `thisArg` and invoked with three
* arguments; (value, key, object). Callbacks may exit iteration early by
* explicitly returning `false`.
*
* @static
* @memberOf _
* @type Function
* @category Objects
* @param {Object} object The object to iterate over.
* @param {Function} [callback=identity] The function called per iteration.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Object} Returns `object`.
* @example
*
* _.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function(num, key){
* console.log(key);
* });
*
*/
var forOwn=function(collection, callback, thisArg){
var index, iterable=collection, result=iterable;
if(!iterable) return result;
if(!objectTypes[typeof iterable]) return result;
callback=callback&&typeof thisArg=='undefined' ? callback:baseCreateCallback(callback, thisArg, 3);
var ownIndex=-1,
ownProps=objectTypes[typeof iterable]&&keys(iterable),
length=ownProps ? ownProps.length:0;
while (++ownIndex < length){
index=ownProps[ownIndex];
if(callback(iterable[index], index, collection)===false) return result;
}
return result
};
/**
* This method is like `_.forOwn` except that it iterates over elements
* of a `collection` in the opposite order.
*
* @static
* @memberOf _
* @category Objects
* @param {Object} object The object to iterate over.
* @param {Function} [callback=identity] The function called per iteration.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Object} Returns `object`.
* @example
*
* _.forOwnRight({ '0': 'zero', '1': 'one', 'length': 2 }, function(num, key){
* console.log(key);
* });
*
*/
function forOwnRight(object, callback, thisArg){
var props=keys(object),
length=props.length;
callback=baseCreateCallback(callback, thisArg, 3);
while (length--){
var key=props[length];
if(callback(object[key], key, object)===false){
break;
}}
return object;
}
function functions(object){
var result=[];
forIn(object, function(value, key){
if(isFunction(value)){
result.push(key);
}});
return result.sort();
}
function has(object, key){
return object ? hasOwnProperty.call(object, key):false;
}
function invert(object){
var index=-1,
props=keys(object),
length=props.length,
result={};
while (++index < length){
var key=props[index];
result[object[key]]=key;
}
return result;
}
function isBoolean(value){
return value===true||value===false ||
value&&typeof value=='object'&&toString.call(value)==boolClass||false;
}
function isDate(value){
return value&&typeof value=='object'&&toString.call(value)==dateClass||false;
}
function isElement(value){
return value&&value.nodeType===1||false;
}
function isEmpty(value){
var result=true;
if(!value){
return result;
}
var className=toString.call(value),
length=value.length;
if((className==arrayClass||className==stringClass||className==argsClass) ||
(className==objectClass&&typeof length=='number'&&isFunction(value.splice))){
return !length;
}
forOwn(value, function(){
return (result=false);
});
return result;
}
/**
* Performs a deep comparison between two values to determine if they are
* equivalent to each other. If a callback is provided it will be executed
* to compare values. If the callback returns `undefined` comparisons will
* be handled by the method instead. The callback is bound to `thisArg` and
* invoked with two arguments; (a, b).
*
* @static
* @memberOf _
* @category Objects
* @param {*} a The value to compare.
* @param {*} b The other value to compare.
* @param {Function} [callback] The function to customize comparing values.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
* @example
*
* var object={ 'name': 'fred' };
* var copy={ 'name': 'fred' };
*
* object==copy;
*
*
* _.isEqual(object, copy);
*
*
* var words=['hello', 'goodbye'];
* var otherWords=['hi', 'goodbye'];
*
* _.isEqual(words, otherWords, function(a, b){
* var reGreet=/^(?:hello|hi)$/i,
* aGreet=_.isString(a)&&reGreet.test(a),
* bGreet=_.isString(b)&&reGreet.test(b);
*
* return (aGreet||bGreet) ? (aGreet==bGreet):undefined;
* });
*
*/
function isEqual(a, b, callback, thisArg){
return baseIsEqual(a, b, typeof callback=='function'&&baseCreateCallback(callback, thisArg, 2));
}
function isFinite(value){
return nativeIsFinite(value)&&!nativeIsNaN(parseFloat(value));
}
function isFunction(value){
return typeof value=='function';
}
function isObject(value){
return !!(value&&objectTypes[typeof value]);
}
function isNaN(value){
return isNumber(value)&&value!=+value;
}
function isNull(value){
return value===null;
}
function isNumber(value){
return typeof value=='number' ||
value&&typeof value=='object'&&toString.call(value)==numberClass||false;
}
var isPlainObject = !getPrototypeOf ? shimIsPlainObject:function(value){
if(!(value&&toString.call(value)==objectClass)){
return false;
}
var valueOf=value.valueOf,
objProto=isNative(valueOf)&&(objProto=getPrototypeOf(valueOf))&&getPrototypeOf(objProto);
return objProto
? (value==objProto||getPrototypeOf(value)==objProto)
: shimIsPlainObject(value);
};
function isRegExp(value){
return value&&typeof value=='object'&&toString.call(value)==regexpClass||false;
}
function isString(value){
return typeof value=='string' ||
value&&typeof value=='object'&&toString.call(value)==stringClass||false;
}
function isUndefined(value){
return typeof value=='undefined';
}
/**
* Creates an object with the same keys as `object` and values generated by
* running each own enumerable property of `object` through the callback.
* The callback is bound to `thisArg` and invoked with three arguments;
* (value, key, object).
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @category Objects
* @param {Object} object The object to iterate over.
* @param {Function|Object|string} [callback=identity] The function called
* per iteration. If a property name or object is provided it will be used
* to create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Array} Returns a new object with values of the results of each `callback` execution.
* @example
*
* _.mapValues({ 'a': 1, 'b': 2, 'c': 3} , function(num){ return num * 3; });
*
*
* var characters={
* 'fred': { 'name': 'fred', 'age': 40 },
* 'pebbles': { 'name': 'pebbles', 'age': 1 }
* };
*
*
* _.mapValues(characters, 'age');
*
*/
function mapValues(object, callback, thisArg){
var result={};
callback=lodash.createCallback(callback, thisArg, 3);
forOwn(object, function(value, key, object){
result[key]=callback(value, key, object);
});
return result;
}
/**
* Recursively merges own enumerable properties of the source object(s), that
* don't resolve to `undefined` into the destination object. Subsequent sources
* will overwrite property assignments of previous sources. If a callback is
* provided it will be executed to produce the merged values of the destination
* and source properties. If the callback returns `undefined` merging will
* be handled by the method instead. The callback is bound to `thisArg` and
* invoked with two arguments; (objectValue, sourceValue).
*
* @static
* @memberOf _
* @category Objects
* @param {Object} object The destination object.
* @param {...Object} [source] The source objects.
* @param {Function} [callback] The function to customize merging properties.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Object} Returns the destination object.
* @example
*
* var names={
* 'characters': [
* { 'name': 'barney' },
* { 'name': 'fred' }
* ]
* };
*
* var ages={
* 'characters': [
* { 'age': 36 },
* { 'age': 40 }
* ]
* };
*
* _.merge(names, ages);
*
*
* var food={
* 'fruits': ['apple'],
* 'vegetables': ['beet']
* };
*
* var otherFood={
* 'fruits': ['banana'],
* 'vegetables': ['carrot']
* };
*
* _.merge(food, otherFood, function(a, b){
* return _.isArray(a) ? a.concat(b):undefined;
* });
*
*/
function merge(object){
var args=arguments,
length=2;
if(!isObject(object)){
return object;
}
if(typeof args[2]!='number'){
length=args.length;
}
if(length > 3&&typeof args[length - 2]=='function'){
var callback=baseCreateCallback(args[--length - 1], args[length--], 2);
}else if(length > 2&&typeof args[length - 1]=='function'){
callback=args[--length];
}
var sources=slice(arguments, 1, length),
index=-1,
stackA=getArray(),
stackB=getArray();
while (++index < length){
baseMerge(object, sources[index], callback, stackA, stackB);
}
releaseArray(stackA);
releaseArray(stackB);
return object;
}
/**
* Creates a shallow clone of `object` excluding the specified properties.
* Property names may be specified as individual arguments or as arrays of
* property names. If a callback is provided it will be executed for each
* property of `object` omitting the properties the callback returns truey
* for. The callback is bound to `thisArg` and invoked with three arguments;
* (value, key, object).
*
* @static
* @memberOf _
* @category Objects
* @param {Object} object The source object.
* @param {Function|...string|string[]} [callback] The properties to omit or the
* function called per iteration.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Object} Returns an object without the omitted properties.
* @example
*
* _.omit({ 'name': 'fred', 'age': 40 }, 'age');
*
*
* _.omit({ 'name': 'fred', 'age': 40 }, function(value){
* return typeof value=='number';
* });
*
*/
function omit(object, callback, thisArg){
var result={};
if(typeof callback!='function'){
var props=[];
forIn(object, function(value, key){
props.push(key);
});
props=baseDifference(props, baseFlatten(arguments, true, false, 1));
var index=-1,
length=props.length;
while (++index < length){
var key=props[index];
result[key]=object[key];
}}else{
callback=lodash.createCallback(callback, thisArg, 3);
forIn(object, function(value, key, object){
if(!callback(value, key, object)){
result[key]=value;
}});
}
return result;
}
function pairs(object){
var index=-1,
props=keys(object),
length=props.length,
result=Array(length);
while (++index < length){
var key=props[index];
result[index]=[key, object[key]];
}
return result;
}
/**
* Creates a shallow clone of `object` composed of the specified properties.
* Property names may be specified as individual arguments or as arrays of
* property names. If a callback is provided it will be executed for each
* property of `object` picking the properties the callback returns truey
* for. The callback is bound to `thisArg` and invoked with three arguments;
* (value, key, object).
*
* @static
* @memberOf _
* @category Objects
* @param {Object} object The source object.
* @param {Function|...string|string[]} [callback] The function called per
* iteration or property names to pick, specified as individual property
* names or arrays of property names.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Object} Returns an object composed of the picked properties.
* @example
*
* _.pick({ 'name': 'fred', '_userid': 'fred1' }, 'name');
*
*
* _.pick({ 'name': 'fred', '_userid': 'fred1' }, function(value, key){
* return key.charAt(0)!='_';
* });
*
*/
function pick(object, callback, thisArg){
var result={};
if(typeof callback!='function'){
var index=-1,
props=baseFlatten(arguments, true, false, 1),
length=isObject(object) ? props.length:0;
while (++index < length){
var key=props[index];
if(key in object){
result[key]=object[key];
}}
}else{
callback=lodash.createCallback(callback, thisArg, 3);
forIn(object, function(value, key, object){
if(callback(value, key, object)){
result[key]=value;
}});
}
return result;
}
/**
* An alternative to `_.reduce` this method transforms `object` to a new
* `accumulator` object which is the result of running each of its own
* enumerable properties through a callback, with each callback execution
* potentially mutating the `accumulator` object. The callback is bound to
* `thisArg` and invoked with four arguments; (accumulator, value, key, object).
* Callbacks may exit iteration early by explicitly returning `false`.
*
* @static
* @memberOf _
* @category Objects
* @param {Array|Object} object The object to iterate over.
* @param {Function} [callback=identity] The function called per iteration.
* @param {*} [accumulator] The custom accumulator value.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {*} Returns the accumulated value.
* @example
*
* var squares=_.transform([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], function(result, num){
* num *=num;
* if(num % 2){
* return result.push(num) < 3;
* }
* });
*
*
* var mapped=_.transform({ 'a': 1, 'b': 2, 'c': 3 }, function(result, num, key){
* result[key]=num * 3;
* });
*
*/
function transform(object, callback, accumulator, thisArg){
var isArr=isArray(object);
if(accumulator==null){
if(isArr){
accumulator=[];
}else{
var ctor=object&&object.constructor,
proto=ctor&&ctor.prototype;
accumulator=baseCreate(proto);
}}
if(callback){
callback=lodash.createCallback(callback, thisArg, 4);
(isArr ? forEach:forOwn)(object, function(value, index, object){
return callback(accumulator, value, index, object);
});
}
return accumulator;
}
function values(object){
var index=-1,
props=keys(object),
length=props.length,
result=Array(length);
while (++index < length){
result[index]=object[props[index]];
}
return result;
}
function at(collection){
var args=arguments,
index=-1,
props=baseFlatten(args, true, false, 1),
length=(args[2]&&args[2][args[1]]===collection) ? 1:props.length,
result=Array(length);
while(++index < length){
result[index]=collection[props[index]];
}
return result;
}
function contains(collection, target, fromIndex){
var index=-1,
indexOf=getIndexOf(),
length=collection ? collection.length:0,
result=false;
fromIndex=(fromIndex < 0 ? nativeMax(0, length + fromIndex):fromIndex)||0;
if(isArray(collection)){
result=indexOf(collection, target, fromIndex) > -1;
}else if(typeof length=='number'){
result=(isString(collection) ? collection.indexOf(target, fromIndex):indexOf(collection, target, fromIndex)) > -1;
}else{
forOwn(collection, function(value){
if(++index >=fromIndex){
return !(result=value===target);
}});
}
return result;
}
/**
* Creates an object composed of keys generated from the results of running
* each element of `collection` through the callback. The corresponding value
* of each key is the number of times the key was returned by the callback.
* The callback is bound to `thisArg` and invoked with three arguments;
* (value, index|key, collection).
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @category Collections
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [callback=identity] The function called
* per iteration. If a property name or object is provided it will be used
* to create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Object} Returns the composed aggregate object.
* @example
*
* _.countBy([4.3, 6.1, 6.4], function(num){ return Math.floor(num); });
*
*
* _.countBy([4.3, 6.1, 6.4], function(num){ return this.floor(num); }, Math);
*
*
* _.countBy(['one', 'two', 'three'], 'length');
*
*/
var countBy=createAggregator(function(result, value, key){
(hasOwnProperty.call(result, key) ? result[key]++:result[key]=1);
});
function every(collection, callback, thisArg){
var result=true;
callback=lodash.createCallback(callback, thisArg, 3);
var index=-1,
length=collection ? collection.length:0;
if(typeof length=='number'){
while (++index < length){
if(!(result = !!callback(collection[index], index, collection))){
break;
}}
}else{
forOwn(collection, function(value, index, collection){
return (result = !!callback(value, index, collection));
});
}
return result;
}
/**
* Iterates over elements of a collection, returning an array of all elements
* the callback returns truey for. The callback is bound to `thisArg` and
* invoked with three arguments; (value, index|key, collection).
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @alias select
* @category Collections
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [callback=identity] The function called
* per iteration. If a property name or object is provided it will be used
* to create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Array} Returns a new array of elements that passed the callback check.
* @example
*
* var evens=_.filter([1, 2, 3, 4, 5, 6], function(num){ return num % 2==0; });
*
*
* var characters=[
* { 'name': 'barney', 'age': 36, 'blocked': false },
* { 'name': 'fred', 'age': 40, 'blocked': true }
* ];
*
*
* _.filter(characters, 'blocked');
*
*
*
* _.filter(characters, { 'age': 36 });
*
*/
function filter(collection, callback, thisArg){
var result=[];
callback=lodash.createCallback(callback, thisArg, 3);
var index=-1,
length=collection ? collection.length:0;
if(typeof length=='number'){
while (++index < length){
var value=collection[index];
if(callback(value, index, collection)){
result.push(value);
}}
}else{
forOwn(collection, function(value, index, collection){
if(callback(value, index, collection)){
result.push(value);
}});
}
return result;
}
/**
* Iterates over elements of a collection, returning the first element that
* the callback returns truey for. The callback is bound to `thisArg` and
* invoked with three arguments; (value, index|key, collection).
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @alias detect, findWhere
* @category Collections
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [callback=identity] The function called
* per iteration. If a property name or object is provided it will be used
* to create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {*} Returns the found element, else `undefined`.
* @example
*
* var characters=[
* { 'name': 'barney', 'age': 36, 'blocked': false },
* { 'name': 'fred', 'age': 40, 'blocked': true },
* { 'name': 'pebbles', 'age': 1, 'blocked': false }
* ];
*
* _.find(characters, function(chr){
* return chr.age < 40;
* });
*
*
*
* _.find(characters, { 'age': 1 });
*
*
*
* _.find(characters, 'blocked');
*
*/
function find(collection, callback, thisArg){
callback=lodash.createCallback(callback, thisArg, 3);
var index=-1,
length=collection ? collection.length:0;
if(typeof length=='number'){
while (++index < length){
var value=collection[index];
if(callback(value, index, collection)){
return value;
}}
}else{
var result;
forOwn(collection, function(value, index, collection){
if(callback(value, index, collection)){
result=value;
return false;
}});
return result;
}}
/**
* This method is like `_.find` except that it iterates over elements
* of a `collection` from right to left.
*
* @static
* @memberOf _
* @category Collections
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [callback=identity] The function called
* per iteration. If a property name or object is provided it will be used
* to create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {*} Returns the found element, else `undefined`.
* @example
*
* _.findLast([1, 2, 3, 4], function(num){
* return num % 2==1;
* });
*
*/
function findLast(collection, callback, thisArg){
var result;
callback=lodash.createCallback(callback, thisArg, 3);
forEachRight(collection, function(value, index, collection){
if(callback(value, index, collection)){
result=value;
return false;
}});
return result;
}
/**
* Iterates over elements of a collection, executing the callback for each
* element. The callback is bound to `thisArg` and invoked with three arguments;
* (value, index|key, collection). Callbacks may exit iteration early by
* explicitly returning `false`.
*
* Note: As with other "Collections" methods, objects with a `length` property
* are iterated like arrays. To avoid this behavior `_.forIn` or `_.forOwn`
* may be used for object iteration.
*
* @static
* @memberOf _
* @alias each
* @category Collections
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function} [callback=identity] The function called per iteration.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Array|Object|string} Returns `collection`.
* @example
*
* _([1, 2, 3]).forEach(function(num){ console.log(num); }).join(',');
*
*
* _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, function(num){ console.log(num); });
*
*/
function forEach(collection, callback, thisArg){
var index=-1,
length=collection ? collection.length:0;
callback=callback&&typeof thisArg=='undefined' ? callback:baseCreateCallback(callback, thisArg, 3);
if(typeof length=='number'){
while (++index < length){
if(callback(collection[index], index, collection)===false){
break;
}}
}else{
forOwn(collection, callback);
}
return collection;
}
/**
* This method is like `_.forEach` except that it iterates over elements
* of a `collection` from right to left.
*
* @static
* @memberOf _
* @alias eachRight
* @category Collections
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function} [callback=identity] The function called per iteration.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Array|Object|string} Returns `collection`.
* @example
*
* _([1, 2, 3]).forEachRight(function(num){ console.log(num); }).join(',');
*
*/
function forEachRight(collection, callback, thisArg){
var length=collection ? collection.length:0;
callback=callback&&typeof thisArg=='undefined' ? callback:baseCreateCallback(callback, thisArg, 3);
if(typeof length=='number'){
while (length--){
if(callback(collection[length], length, collection)===false){
break;
}}
}else{
var props=keys(collection);
length=props.length;
forOwn(collection, function(value, key, collection){
key=props ? props[--length]:--length;
return callback(collection[key], key, collection);
});
}
return collection;
}
/**
* Creates an object composed of keys generated from the results of running
* each element of a collection through the callback. The corresponding value
* of each key is an array of the elements responsible for generating the key.
* The callback is bound to `thisArg` and invoked with three arguments;
* (value, index|key, collection).
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`
*
* @static
* @memberOf _
* @category Collections
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [callback=identity] The function called
* per iteration. If a property name or object is provided it will be used
* to create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Object} Returns the composed aggregate object.
* @example
*
* _.groupBy([4.2, 6.1, 6.4], function(num){ return Math.floor(num); });
*
*
* _.groupBy([4.2, 6.1, 6.4], function(num){ return this.floor(num); }, Math);
*
*
*
* _.groupBy(['one', 'two', 'three'], 'length');
*
*/
var groupBy=createAggregator(function(result, value, key){
(hasOwnProperty.call(result, key) ? result[key]:result[key]=[]).push(value);
});
/**
* Creates an object composed of keys generated from the results of running
* each element of the collection through the given callback. The corresponding
* value of each key is the last element responsible for generating the key.
* The callback is bound to `thisArg` and invoked with three arguments;
* (value, index|key, collection).
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @category Collections
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [callback=identity] The function called
* per iteration. If a property name or object is provided it will be used
* to create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Object} Returns the composed aggregate object.
* @example
*
* var keys=[
* { 'dir': 'left', 'code': 97 },
* { 'dir': 'right', 'code': 100 }
* ];
*
* _.indexBy(keys, 'dir');
*
*
* _.indexBy(keys, function(key){ return String.fromCharCode(key.code); });
*
*
* _.indexBy(characters, function(key){ this.fromCharCode(key.code); }, String);
*
*/
var indexBy=createAggregator(function(result, value, key){
result[key]=value;
});
/**
* Invokes the method named by `methodName` on each element in the `collection`
* returning an array of the results of each invoked method. Additional arguments
* will be provided to each invoked method. If `methodName` is a function it
* will be invoked for, and `this` bound to, each element in the `collection`.
*
* @static
* @memberOf _
* @category Collections
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|string} methodName The name of the method to invoke or
* the function invoked per iteration.
* @param {...*} [arg] Arguments to invoke the method with.
* @returns {Array} Returns a new array of the results of each invoked method.
* @example
*
* _.invoke([[5, 1, 7], [3, 2, 1]], 'sort');
*
*
* _.invoke([123, 456], String.prototype.split, '');
*
*/
function invoke(collection, methodName){
var args=slice(arguments, 2),
index=-1,
isFunc=typeof methodName=='function',
length=collection ? collection.length:0,
result=Array(typeof length=='number' ? length:0);
forEach(collection, function(value){
result[++index]=(isFunc ? methodName:value[methodName]).apply(value, args);
});
return result;
}
/**
* Creates an array of values by running each element in the collection
* through the callback. The callback is bound to `thisArg` and invoked with
* three arguments; (value, index|key, collection).
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @alias collect
* @category Collections
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [callback=identity] The function called
* per iteration. If a property name or object is provided it will be used
* to create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Array} Returns a new array of the results of each `callback` execution.
* @example
*
* _.map([1, 2, 3], function(num){ return num * 3; });
*
*
* _.map({ 'one': 1, 'two': 2, 'three': 3 }, function(num){ return num * 3; });
*
*
* var characters=[
* { 'name': 'barney', 'age': 36 },
* { 'name': 'fred', 'age': 40 }
* ];
*
*
* _.map(characters, 'name');
*
*/
function map(collection, callback, thisArg){
var index=-1,
length=collection ? collection.length:0;
callback=lodash.createCallback(callback, thisArg, 3);
if(typeof length=='number'){
var result=Array(length);
while (++index < length){
result[index]=callback(collection[index], index, collection);
}}else{
result=[];
forOwn(collection, function(value, key, collection){
result[++index]=callback(value, key, collection);
});
}
return result;
}
/**
* Retrieves the maximum value of a collection. If the collection is empty or
* falsey `-Infinity` is returned. If a callback is provided it will be executed
* for each value in the collection to generate the criterion by which the value
* is ranked. The callback is bound to `thisArg` and invoked with three
* arguments; (value, index, collection).
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @category Collections
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [callback=identity] The function called
* per iteration. If a property name or object is provided it will be used
* to create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {*} Returns the maximum value.
* @example
*
* _.max([4, 2, 8, 6]);
*
*
* var characters=[
* { 'name': 'barney', 'age': 36 },
* { 'name': 'fred', 'age': 40 }
* ];
*
* _.max(characters, function(chr){ return chr.age; });
*
*
*
* _.max(characters, 'age');
*
*/
function max(collection, callback, thisArg){
var computed=-Infinity,
result=computed;
if(typeof callback!='function'&&thisArg&&thisArg[callback]===collection){
callback=null;
}
if(callback==null&&isArray(collection)){
var index=-1,
length=collection.length;
while (++index < length){
var value=collection[index];
if(value > result){
result=value;
}}
}else{
callback=(callback==null&&isString(collection))
? charAtCallback
: lodash.createCallback(callback, thisArg, 3);
forEach(collection, function(value, index, collection){
var current=callback(value, index, collection);
if(current > computed){
computed=current;
result=value;
}});
}
return result;
}
/**
* Retrieves the minimum value of a collection. If the collection is empty or
* falsey `Infinity` is returned. If a callback is provided it will be executed
* for each value in the collection to generate the criterion by which the value
* is ranked. The callback is bound to `thisArg` and invoked with three
* arguments; (value, index, collection).
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @category Collections
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [callback=identity] The function called
* per iteration. If a property name or object is provided it will be used
* to create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {*} Returns the minimum value.
* @example
*
* _.min([4, 2, 8, 6]);
*
*
* var characters=[
* { 'name': 'barney', 'age': 36 },
* { 'name': 'fred', 'age': 40 }
* ];
*
* _.min(characters, function(chr){ return chr.age; });
*
*
*
* _.min(characters, 'age');
*
*/
function min(collection, callback, thisArg){
var computed=Infinity,
result=computed;
if(typeof callback!='function'&&thisArg&&thisArg[callback]===collection){
callback=null;
}
if(callback==null&&isArray(collection)){
var index=-1,
length=collection.length;
while (++index < length){
var value=collection[index];
if(value < result){
result=value;
}}
}else{
callback=(callback==null&&isString(collection))
? charAtCallback
: lodash.createCallback(callback, thisArg, 3);
forEach(collection, function(value, index, collection){
var current=callback(value, index, collection);
if(current < computed){
computed=current;
result=value;
}});
}
return result;
}
var pluck=map;
/**
* Reduces a collection to a value which is the accumulated result of running
* each element in the collection through the callback, where each successive
* callback execution consumes the return value of the previous execution. If
* `accumulator` is not provided the first element of the collection will be
* used as the initial `accumulator` value. The callback is bound to `thisArg`
* and invoked with four arguments; (accumulator, value, index|key, collection).
*
* @static
* @memberOf _
* @alias foldl, inject
* @category Collections
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function} [callback=identity] The function called per iteration.
* @param {*} [accumulator] Initial value of the accumulator.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {*} Returns the accumulated value.
* @example
*
* var sum=_.reduce([1, 2, 3], function(sum, num){
* return sum + num;
* });
*
*
* var mapped=_.reduce({ 'a': 1, 'b': 2, 'c': 3 }, function(result, num, key){
* result[key]=num * 3;
* return result;
* }, {});
*
*/
function reduce(collection, callback, accumulator, thisArg){
if(!collection) return accumulator;
var noaccum=arguments.length < 3;
callback=lodash.createCallback(callback, thisArg, 4);
var index=-1,
length=collection.length;
if(typeof length=='number'){
if(noaccum){
accumulator=collection[++index];
}
while (++index < length){
accumulator=callback(accumulator, collection[index], index, collection);
}}else{
forOwn(collection, function(value, index, collection){
accumulator=noaccum
? (noaccum=false, value)
: callback(accumulator, value, index, collection)
});
}
return accumulator;
}
/**
* This method is like `_.reduce` except that it iterates over elements
* of a `collection` from right to left.
*
* @static
* @memberOf _
* @alias foldr
* @category Collections
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function} [callback=identity] The function called per iteration.
* @param {*} [accumulator] Initial value of the accumulator.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {*} Returns the accumulated value.
* @example
*
* var list=[[0, 1], [2, 3], [4, 5]];
* var flat=_.reduceRight(list, function(a, b){ return a.concat(b); }, []);
*
*/
function reduceRight(collection, callback, accumulator, thisArg){
var noaccum=arguments.length < 3;
callback=lodash.createCallback(callback, thisArg, 4);
forEachRight(collection, function(value, index, collection){
accumulator=noaccum
? (noaccum=false, value)
: callback(accumulator, value, index, collection);
});
return accumulator;
}
/**
* The opposite of `_.filter` this method returns the elements of a
* collection that the callback does **not** return truey for.
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @category Collections
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [callback=identity] The function called
* per iteration. If a property name or object is provided it will be used
* to create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Array} Returns a new array of elements that failed the callback check.
* @example
*
* var odds=_.reject([1, 2, 3, 4, 5, 6], function(num){ return num % 2==0; });
*
*
* var characters=[
* { 'name': 'barney', 'age': 36, 'blocked': false },
* { 'name': 'fred', 'age': 40, 'blocked': true }
* ];
*
*
* _.reject(characters, 'blocked');
*
*
*
* _.reject(characters, { 'age': 36 });
*
*/
function reject(collection, callback, thisArg){
callback=lodash.createCallback(callback, thisArg, 3);
return filter(collection, function(value, index, collection){
return !callback(value, index, collection);
});
}
function sample(collection, n, guard){
if(collection&&typeof collection.length!='number'){
collection=values(collection);
}
if(n==null||guard){
return collection ? collection[baseRandom(0, collection.length - 1)]:undefined;
}
var result=shuffle(collection);
result.length=nativeMin(nativeMax(0, n), result.length);
return result;
}
function shuffle(collection){
var index=-1,
length=collection ? collection.length:0,
result=Array(typeof length=='number' ? length:0);
forEach(collection, function(value){
var rand=baseRandom(0, ++index);
result[index]=result[rand];
result[rand]=value;
});
return result;
}
function size(collection){
var length=collection ? collection.length:0;
return typeof length=='number' ? length:keys(collection).length;
}
function some(collection, callback, thisArg){
var result;
callback=lodash.createCallback(callback, thisArg, 3);
var index=-1,
length=collection ? collection.length:0;
if(typeof length=='number'){
while (++index < length){
if((result=callback(collection[index], index, collection))){
break;
}}
}else{
forOwn(collection, function(value, index, collection){
return !(result=callback(value, index, collection));
});
}
return !!result;
}
/**
* Creates an array of elements, sorted in ascending order by the results of
* running each element in a collection through the callback. This method
* performs a stable sort, that is, it will preserve the original sort order
* of equal elements. The callback is bound to `thisArg` and invoked with
* three arguments; (value, index|key, collection).
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an array of property names is provided for `callback` the collection
* will be sorted by each property value.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @category Collections
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Array|Function|Object|string} [callback=identity] The function called
* per iteration. If a property name or object is provided it will be used
* to create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Array} Returns a new array of sorted elements.
* @example
*
* _.sortBy([1, 2, 3], function(num){ return Math.sin(num); });
*
*
* _.sortBy([1, 2, 3], function(num){ return this.sin(num); }, Math);
*
*
* var characters=[
* { 'name': 'barney', 'age': 36 },
* { 'name': 'fred', 'age': 40 },
* { 'name': 'barney', 'age': 26 },
* { 'name': 'fred', 'age': 30 }
* ];
*
*
* _.map(_.sortBy(characters, 'age'), _.values);
*
*
*
* _.map(_.sortBy(characters, ['name', 'age']), _.values);
*
*/
function sortBy(collection, callback, thisArg){
var index=-1,
isArr=isArray(callback),
length=collection ? collection.length:0,
result=Array(typeof length=='number' ? length:0);
if(!isArr){
callback=lodash.createCallback(callback, thisArg, 3);
}
forEach(collection, function(value, key, collection){
var object=result[++index]=getObject();
if(isArr){
object.criteria=map(callback, function(key){ return value[key]; });
}else{
(object.criteria=getArray())[0]=callback(value, key, collection);
}
object.index=index;
object.value=value;
});
length=result.length;
result.sort(compareAscending);
while (length--){
var object=result[length];
result[length]=object.value;
if(!isArr){
releaseArray(object.criteria);
}
releaseObject(object);
}
return result;
}
/**
* Converts the `collection` to an array.
*
* @static
* @memberOf _
* @category Collections
* @param {Array|Object|string} collection The collection to convert.
* @returns {Array} Returns the new converted array.
* @example
*
* (function(){ return _.toArray(arguments).slice(1); })(1, 2, 3, 4);
*
*/
function toArray(collection){
if(collection&&typeof collection.length=='number'){
return slice(collection);
}
return values(collection);
}
var where=filter;
function compact(array){
var index=-1,
length=array ? array.length:0,
result=[];
while (++index < length){
var value=array[index];
if(value){
result.push(value);
}}
return result;
}
function difference(array){
return baseDifference(array, baseFlatten(arguments, true, true, 1));
}
/**
* This method is like `_.find` except that it returns the index of the first
* element that passes the callback check, instead of the element itself.
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @category Arrays
* @param {Array} array The array to search.
* @param {Function|Object|string} [callback=identity] The function called
* per iteration. If a property name or object is provided it will be used
* to create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {number} Returns the index of the found element, else `-1`.
* @example
*
* var characters=[
* { 'name': 'barney', 'age': 36, 'blocked': false },
* { 'name': 'fred', 'age': 40, 'blocked': true },
* { 'name': 'pebbles', 'age': 1, 'blocked': false }
* ];
*
* _.findIndex(characters, function(chr){
* return chr.age < 20;
* });
*
*
*
* _.findIndex(characters, { 'age': 36 });
*
*
*
* _.findIndex(characters, 'blocked');
*
*/
function findIndex(array, callback, thisArg){
var index=-1,
length=array ? array.length:0;
callback=lodash.createCallback(callback, thisArg, 3);
while (++index < length){
if(callback(array[index], index, array)){
return index;
}}
return -1;
}
/**
* This method is like `_.findIndex` except that it iterates over elements
* of a `collection` from right to left.
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @category Arrays
* @param {Array} array The array to search.
* @param {Function|Object|string} [callback=identity] The function called
* per iteration. If a property name or object is provided it will be used
* to create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {number} Returns the index of the found element, else `-1`.
* @example
*
* var characters=[
* { 'name': 'barney', 'age': 36, 'blocked': true },
* { 'name': 'fred', 'age': 40, 'blocked': false },
* { 'name': 'pebbles', 'age': 1, 'blocked': true }
* ];
*
* _.findLastIndex(characters, function(chr){
* return chr.age > 30;
* });
*
*
*
* _.findLastIndex(characters, { 'age': 36 });
*
*
*
* _.findLastIndex(characters, 'blocked');
*
*/
function findLastIndex(array, callback, thisArg){
var length=array ? array.length:0;
callback=lodash.createCallback(callback, thisArg, 3);
while (length--){
if(callback(array[length], length, array)){
return length;
}}
return -1;
}
/**
* Gets the first element or first `n` elements of an array. If a callback
* is provided elements at the beginning of the array are returned as long
* as the callback returns truey. The callback is bound to `thisArg` and
* invoked with three arguments; (value, index, array).
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @alias head, take
* @category Arrays
* @param {Array} array The array to query.
* @param {Function|Object|number|string} [callback] The function called
* per element or the number of elements to return. If a property name or
* object is provided it will be used to create a "_.pluck" or "_.where"
* style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {*} Returns the first element(s) of `array`.
* @example
*
* _.first([1, 2, 3]);
*
*
* _.first([1, 2, 3], 2);
*
*
* _.first([1, 2, 3], function(num){
* return num < 3;
* });
*
*
* var characters=[
* { 'name': 'barney', 'blocked': true, 'employer': 'slate' },
* { 'name': 'fred', 'blocked': false, 'employer': 'slate' },
* { 'name': 'pebbles', 'blocked': true, 'employer': 'na' }
* ];
*
*
* _.first(characters, 'blocked');
*
*
*
* _.pluck(_.first(characters, { 'employer': 'slate' }), 'name');
*
*/
function first(array, callback, thisArg){
var n=0,
length=array ? array.length:0;
if(typeof callback!='number'&&callback!=null){
var index=-1;
callback=lodash.createCallback(callback, thisArg, 3);
while (++index < length&&callback(array[index], index, array)){
n++;
}}else{
n=callback;
if(n==null||thisArg){
return array ? array[0]:undefined;
}}
return slice(array, 0, nativeMin(nativeMax(0, n), length));
}
function flatten(array, isShallow, callback, thisArg){
if(typeof isShallow!='boolean'&&isShallow!=null){
thisArg=callback;
callback=(typeof isShallow!='function'&&thisArg&&thisArg[isShallow]===array) ? null:isShallow;
isShallow=false;
}
if(callback!=null){
array=map(array, callback, thisArg);
}
return baseFlatten(array, isShallow);
}
function indexOf(array, value, fromIndex){
if(typeof fromIndex=='number'){
var length=array ? array.length:0;
fromIndex=(fromIndex < 0 ? nativeMax(0, length + fromIndex):fromIndex||0);
}else if(fromIndex){
var index=sortedIndex(array, value);
return array[index]===value ? index:-1;
}
return baseIndexOf(array, value, fromIndex);
}
/**
* Gets all but the last element or last `n` elements of an array. If a
* callback is provided elements at the end of the array are excluded from
* the result as long as the callback returns truey. The callback is bound
* to `thisArg` and invoked with three arguments; (value, index, array).
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @category Arrays
* @param {Array} array The array to query.
* @param {Function|Object|number|string} [callback=1] The function called
* per element or the number of elements to exclude. If a property name or
* object is provided it will be used to create a "_.pluck" or "_.where"
* style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Array} Returns a slice of `array`.
* @example
*
* _.initial([1, 2, 3]);
*
*
* _.initial([1, 2, 3], 2);
*
*
* _.initial([1, 2, 3], function(num){
* return num > 1;
* });
*
*
* var characters=[
* { 'name': 'barney', 'blocked': false, 'employer': 'slate' },
* { 'name': 'fred', 'blocked': true, 'employer': 'slate' },
* { 'name': 'pebbles', 'blocked': true, 'employer': 'na' }
* ];
*
*
* _.initial(characters, 'blocked');
*
*
*
* _.pluck(_.initial(characters, { 'employer': 'na' }), 'name');
*
*/
function initial(array, callback, thisArg){
var n=0,
length=array ? array.length:0;
if(typeof callback!='number'&&callback!=null){
var index=length;
callback=lodash.createCallback(callback, thisArg, 3);
while (index--&&callback(array[index], index, array)){
n++;
}}else{
n=(callback==null||thisArg) ? 1:callback||n;
}
return slice(array, 0, nativeMin(nativeMax(0, length - n), length));
}
function intersection(){
var args=[],
argsIndex=-1,
argsLength=arguments.length,
caches=getArray(),
indexOf=getIndexOf(),
trustIndexOf=indexOf===baseIndexOf,
seen=getArray();
while (++argsIndex < argsLength){
var value=arguments[argsIndex];
if(isArray(value)||isArguments(value)){
args.push(value);
caches.push(trustIndexOf&&value.length >=largeArraySize &&
createCache(argsIndex ? args[argsIndex]:seen));
}}
var array=args[0],
index=-1,
length=array ? array.length:0,
result=[];
outer:
while (++index < length){
var cache=caches[0];
value=array[index];
if((cache ? cacheIndexOf(cache, value):indexOf(seen, value)) < 0){
argsIndex=argsLength;
(cache||seen).push(value);
while (--argsIndex){
cache=caches[argsIndex];
if((cache ? cacheIndexOf(cache, value):indexOf(args[argsIndex], value)) < 0){
continue outer;
}}
result.push(value);
}}
while (argsLength--){
cache=caches[argsLength];
if(cache){
releaseObject(cache);
}}
releaseArray(caches);
releaseArray(seen);
return result;
}
/**
* Gets the last element or last `n` elements of an array. If a callback is
* provided elements at the end of the array are returned as long as the
* callback returns truey. The callback is bound to `thisArg` and invoked
* with three arguments; (value, index, array).
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @category Arrays
* @param {Array} array The array to query.
* @param {Function|Object|number|string} [callback] The function called
* per element or the number of elements to return. If a property name or
* object is provided it will be used to create a "_.pluck" or "_.where"
* style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {*} Returns the last element(s) of `array`.
* @example
*
* _.last([1, 2, 3]);
*
*
* _.last([1, 2, 3], 2);
*
*
* _.last([1, 2, 3], function(num){
* return num > 1;
* });
*
*
* var characters=[
* { 'name': 'barney', 'blocked': false, 'employer': 'slate' },
* { 'name': 'fred', 'blocked': true, 'employer': 'slate' },
* { 'name': 'pebbles', 'blocked': true, 'employer': 'na' }
* ];
*
*
* _.pluck(_.last(characters, 'blocked'), 'name');
*
*
*
* _.last(characters, { 'employer': 'na' });
*
*/
function last(array, callback, thisArg){
var n=0,
length=array ? array.length:0;
if(typeof callback!='number'&&callback!=null){
var index=length;
callback=lodash.createCallback(callback, thisArg, 3);
while (index--&&callback(array[index], index, array)){
n++;
}}else{
n=callback;
if(n==null||thisArg){
return array ? array[length - 1]:undefined;
}}
return slice(array, nativeMax(0, length - n));
}
function lastIndexOf(array, value, fromIndex){
var index=array ? array.length:0;
if(typeof fromIndex=='number'){
index=(fromIndex < 0 ? nativeMax(0, index + fromIndex):nativeMin(fromIndex, index - 1)) + 1;
}
while (index--){
if(array[index]===value){
return index;
}}
return -1;
}
function pull(array){
var args=arguments,
argsIndex=0,
argsLength=args.length,
length=array ? array.length:0;
while (++argsIndex < argsLength){
var index=-1,
value=args[argsIndex];
while (++index < length){
if(array[index]===value){
splice.call(array, index--, 1);
length--;
}}
}
return array;
}
function range(start, end, step){
start=+start||0;
step=typeof step=='number' ? step:(+step||1);
if(end==null){
end=start;
start=0;
}
var index=-1,
length=nativeMax(0, ceil((end - start) / (step||1))),
result=Array(length);
while (++index < length){
result[index]=start;
start +=step;
}
return result;
}
/**
* Removes all elements from an array that the callback returns truey for
* and returns an array of removed elements. The callback is bound to `thisArg`
* and invoked with three arguments; (value, index, array).
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @category Arrays
* @param {Array} array The array to modify.
* @param {Function|Object|string} [callback=identity] The function called
* per iteration. If a property name or object is provided it will be used
* to create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Array} Returns a new array of removed elements.
* @example
*
* var array=[1, 2, 3, 4, 5, 6];
* var evens=_.remove(array, function(num){ return num % 2==0; });
*
* console.log(array);
*
*
* console.log(evens);
*
*/
function remove(array, callback, thisArg){
var index=-1,
length=array ? array.length:0,
result=[];
callback=lodash.createCallback(callback, thisArg, 3);
while (++index < length){
var value=array[index];
if(callback(value, index, array)){
result.push(value);
splice.call(array, index--, 1);
length--;
}}
return result;
}
/**
* The opposite of `_.initial` this method gets all but the first element or
* first `n` elements of an array. If a callback function is provided elements
* at the beginning of the array are excluded from the result as long as the
* callback returns truey. The callback is bound to `thisArg` and invoked
* with three arguments; (value, index, array).
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @alias drop, tail
* @category Arrays
* @param {Array} array The array to query.
* @param {Function|Object|number|string} [callback=1] The function called
* per element or the number of elements to exclude. If a property name or
* object is provided it will be used to create a "_.pluck" or "_.where"
* style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Array} Returns a slice of `array`.
* @example
*
* _.rest([1, 2, 3]);
*
*
* _.rest([1, 2, 3], 2);
*
*
* _.rest([1, 2, 3], function(num){
* return num < 3;
* });
*
*
* var characters=[
* { 'name': 'barney', 'blocked': true, 'employer': 'slate' },
* { 'name': 'fred', 'blocked': false, 'employer': 'slate' },
* { 'name': 'pebbles', 'blocked': true, 'employer': 'na' }
* ];
*
*
* _.pluck(_.rest(characters, 'blocked'), 'name');
*
*
*
* _.rest(characters, { 'employer': 'slate' });
*
*/
function rest(array, callback, thisArg){
if(typeof callback!='number'&&callback!=null){
var n=0,
index=-1,
length=array ? array.length:0;
callback=lodash.createCallback(callback, thisArg, 3);
while (++index < length&&callback(array[index], index, array)){
n++;
}}else{
n=(callback==null||thisArg) ? 1:nativeMax(0, callback);
}
return slice(array, n);
}
/**
* Uses a binary search to determine the smallest index at which a value
* should be inserted into a given sorted array in order to maintain the sort
* order of the array. If a callback is provided it will be executed for
* `value` and each element of `array` to compute their sort ranking. The
* callback is bound to `thisArg` and invoked with one argument; (value).
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @category Arrays
* @param {Array} array The array to inspect.
* @param {*} value The value to evaluate.
* @param {Function|Object|string} [callback=identity] The function called
* per iteration. If a property name or object is provided it will be used
* to create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {number} Returns the index at which `value` should be inserted
* into `array`.
* @example
*
* _.sortedIndex([20, 30, 50], 40);
*
*
*
* _.sortedIndex([{ 'x': 20 }, { 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x');
*
*
* var dict={
* 'wordToNumber': { 'twenty': 20, 'thirty': 30, 'fourty': 40, 'fifty': 50 }
* };
*
* _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function(word){
* return dict.wordToNumber[word];
* });
*
*
* _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function(word){
* return this.wordToNumber[word];
* }, dict);
*
*/
function sortedIndex(array, value, callback, thisArg){
var low=0,
high=array ? array.length:low;
callback=callback ? lodash.createCallback(callback, thisArg, 1):identity;
value=callback(value);
while (low < high){
var mid=(low + high) >>> 1;
(callback(array[mid]) < value)
? low=mid + 1
: high=mid;
}
return low;
}
function union(){
return baseUniq(baseFlatten(arguments, true, true));
}
/**
* Creates a duplicate-value-free version of an array using strict equality
* for comparisons, i.e. `===`. If the array is sorted, providing
* `true` for `isSorted` will use a faster algorithm. If a callback is provided
* each element of `array` is passed through the callback before uniqueness
* is computed. The callback is bound to `thisArg` and invoked with three
* arguments; (value, index, array).
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @alias unique
* @category Arrays
* @param {Array} array The array to process.
* @param {boolean} [isSorted=false] A flag to indicate that `array` is sorted.
* @param {Function|Object|string} [callback=identity] The function called
* per iteration. If a property name or object is provided it will be used
* to create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Array} Returns a duplicate-value-free array.
* @example
*
* _.uniq([1, 2, 1, 3, 1]);
*
*
* _.uniq([1, 1, 2, 2, 3], true);
*
*
* _.uniq(['A', 'b', 'C', 'a', 'B', 'c'], function(letter){ return letter.toLowerCase(); });
*
*
* _.uniq([1, 2.5, 3, 1.5, 2, 3.5], function(num){ return this.floor(num); }, Math);
*
*
*
* _.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
*
*/
function uniq(array, isSorted, callback, thisArg){
if(typeof isSorted!='boolean'&&isSorted!=null){
thisArg=callback;
callback=(typeof isSorted!='function'&&thisArg&&thisArg[isSorted]===array) ? null:isSorted;
isSorted=false;
}
if(callback!=null){
callback=lodash.createCallback(callback, thisArg, 3);
}
return baseUniq(array, isSorted, callback);
}
function without(array){
return baseDifference(array, slice(arguments, 1));
}
function xor(){
var index=-1,
length=arguments.length;
while (++index < length){
var array=arguments[index];
if(isArray(array)||isArguments(array)){
var result=result
? baseUniq(baseDifference(result, array).concat(baseDifference(array, result)))
: array;
}}
return result||[];
}
function zip(){
var array=arguments.length > 1 ? arguments:arguments[0],
index=-1,
length=array ? max(pluck(array, 'length')):0,
result=Array(length < 0 ? 0:length);
while (++index < length){
result[index]=pluck(array, index);
}
return result;
}
function zipObject(keys, values){
var index=-1,
length=keys ? keys.length:0,
result={};
if(!values&&length&&!isArray(keys[0])){
values=[];
}
while (++index < length){
var key=keys[index];
if(values){
result[key]=values[index];
}else if(key){
result[key[0]]=key[1];
}}
return result;
}
/**
* Creates a function that executes `func`, with the `this` binding and
* arguments of the created function, only after being called `n` times.
*
* @static
* @memberOf _
* @category Functions
* @param {number} n The number of times the function must be called before
* `func` is executed.
* @param {Function} func The function to restrict.
* @returns {Function} Returns the new restricted function.
* @example
*
* var saves=['profile', 'settings'];
*
* var done=_.after(saves.length, function(){
* console.log('Done saving!');
* });
*
* _.forEach(saves, function(type){
* asyncSave({ 'type': type, 'complete': done });
* });
*
*/
function after(n, func){
if(!isFunction(func)){
throw new TypeError;
}
return function(){
if(--n < 1){
return func.apply(this, arguments);
}};}
/**
* Creates a function that, when called, invokes `func` with the `this`
* binding of `thisArg` and prepends any additional `bind` arguments to those
* provided to the bound function.
*
* @static
* @memberOf _
* @category Functions
* @param {Function} func The function to bind.
* @param {*} [thisArg] The `this` binding of `func`.
* @param {...*} [arg] Arguments to be partially applied.
* @returns {Function} Returns the new bound function.
* @example
*
* var func=function(greeting){
* return greeting + ' ' + this.name;
* };
*
* func=_.bind(func, { 'name': 'fred' }, 'hi');
* func();
*
*/
function bind(func, thisArg){
return arguments.length > 2
? createWrapper(func, 17, slice(arguments, 2), null, thisArg)
: createWrapper(func, 1, null, null, thisArg);
}
/**
* Binds methods of an object to the object itself, overwriting the existing
* method. Method names may be specified as individual arguments or as arrays
* of method names. If no method names are provided all the function properties
* of `object` will be bound.
*
* @static
* @memberOf _
* @category Functions
* @param {Object} object The object to bind and assign the bound methods to.
* @param {...string} [methodName] The object method names to
* bind, specified as individual method names or arrays of method names.
* @returns {Object} Returns `object`.
* @example
*
* var view={
* 'label': 'docs',
* 'onClick': function(){ console.log('clicked ' + this.label); }
* };
*
* _.bindAll(view);
* jQuery('#docs').on('click', view.onClick);
*
*/
function bindAll(object){
var funcs=arguments.length > 1 ? baseFlatten(arguments, true, false, 1):functions(object),
index=-1,
length=funcs.length;
while (++index < length){
var key=funcs[index];
object[key]=createWrapper(object[key], 1, null, null, object);
}
return object;
}
/**
* Creates a function that, when called, invokes the method at `object[key]`
* and prepends any additional `bindKey` arguments to those provided to the bound
* function. This method differs from `_.bind` by allowing bound functions to
* reference methods that will be redefined or don't yet exist.
* See http://michaux.ca/articles/lazy-function-definition-pattern.
*
* @static
* @memberOf _
* @category Functions
* @param {Object} object The object the method belongs to.
* @param {string} key The key of the method.
* @param {...*} [arg] Arguments to be partially applied.
* @returns {Function} Returns the new bound function.
* @example
*
* var object={
* 'name': 'fred',
* 'greet': function(greeting){
* return greeting + ' ' + this.name;
* }
* };
*
* var func=_.bindKey(object, 'greet', 'hi');
* func();
*
*
* object.greet=function(greeting){
* return greeting + 'ya ' + this.name + '!';
* };
*
* func();
*
*/
function bindKey(object, key){
return arguments.length > 2
? createWrapper(key, 19, slice(arguments, 2), null, object)
: createWrapper(key, 3, null, null, object);
}
/**
* Creates a function that is the composition of the provided functions,
* where each function consumes the return value of the function that follows.
* For example, composing the functions `f()`, `g()`, and `h()` produces `f(g(h()))`.
* Each function is executed with the `this` binding of the composed function.
*
* @static
* @memberOf _
* @category Functions
* @param {...Function} [func] Functions to compose.
* @returns {Function} Returns the new composed function.
* @example
*
* var realNameMap={
* 'pebbles': 'penelope'
* };
*
* var format=function(name){
* name=realNameMap[name.toLowerCase()]||name;
* return name.charAt(0).toUpperCase() + name.slice(1).toLowerCase();
* };
*
* var greet=function(formatted){
* return 'Hiya ' + formatted + '!';
* };
*
* var welcome=_.compose(greet, format);
* welcome('pebbles');
*
*/
function compose(){
var funcs=arguments,
length=funcs.length;
while (length--){
if(!isFunction(funcs[length])){
throw new TypeError;
}}
return function(){
var args=arguments,
length=funcs.length;
while (length--){
args=[funcs[length].apply(this, args)];
}
return args[0];
};}
/**
* Creates a function which accepts one or more arguments of `func` that when
* invoked either executes `func` returning its result, if all `func` arguments
* have been provided, or returns a function that accepts one or more of the
* remaining `func` arguments, and so on. The arity of `func` can be specified
* if `func.length` is not sufficient.
*
* @static
* @memberOf _
* @category Functions
* @param {Function} func The function to curry.
* @param {number} [arity=func.length] The arity of `func`.
* @returns {Function} Returns the new curried function.
* @example
*
* var curried=_.curry(function(a, b, c){
* console.log(a + b + c);
* });
*
* curried(1)(2)(3);
*
*
* curried(1, 2)(3);
*
*
* curried(1, 2, 3);
*
*/
function curry(func, arity){
arity=typeof arity=='number' ? arity:(+arity||func.length);
return createWrapper(func, 4, null, null, null, arity);
}
function debounce(func, wait, options){
var args,
maxTimeoutId,
result,
stamp,
thisArg,
timeoutId,
trailingCall,
lastCalled=0,
maxWait=false,
trailing=true;
if(!isFunction(func)){
throw new TypeError;
}
wait=nativeMax(0, wait)||0;
if(options===true){
var leading=true;
trailing=false;
}else if(isObject(options)){
leading=options.leading;
maxWait='maxWait' in options&&(nativeMax(wait, options.maxWait)||0);
trailing='trailing' in options ? options.trailing:trailing;
}
var delayed=function(){
var remaining=wait - (now() - stamp);
if(remaining <=0){
if(maxTimeoutId){
clearTimeout(maxTimeoutId);
}
var isCalled=trailingCall;
maxTimeoutId=timeoutId=trailingCall=undefined;
if(isCalled){
lastCalled=now();
result=func.apply(thisArg, args);
if(!timeoutId&&!maxTimeoutId){
args=thisArg=null;
}}
}else{
timeoutId=setTimeout(delayed, remaining);
}};
var maxDelayed=function(){
if(timeoutId){
clearTimeout(timeoutId);
}
maxTimeoutId=timeoutId=trailingCall=undefined;
if(trailing||(maxWait!==wait)){
lastCalled=now();
result=func.apply(thisArg, args);
if(!timeoutId&&!maxTimeoutId){
args=thisArg=null;
}}
};
return function(){
args=arguments;
stamp=now();
thisArg=this;
trailingCall=trailing&&(timeoutId||!leading);
if(maxWait===false){
var leadingCall=leading&&!timeoutId;
}else{
if(!maxTimeoutId&&!leading){
lastCalled=stamp;
}
var remaining=maxWait - (stamp - lastCalled),
isCalled=remaining <=0;
if(isCalled){
if(maxTimeoutId){
maxTimeoutId=clearTimeout(maxTimeoutId);
}
lastCalled=stamp;
result=func.apply(thisArg, args);
}
else if(!maxTimeoutId){
maxTimeoutId=setTimeout(maxDelayed, remaining);
}}
if(isCalled&&timeoutId){
timeoutId=clearTimeout(timeoutId);
}
else if(!timeoutId&&wait!==maxWait){
timeoutId=setTimeout(delayed, wait);
}
if(leadingCall){
isCalled=true;
result=func.apply(thisArg, args);
}
if(isCalled&&!timeoutId&&!maxTimeoutId){
args=thisArg=null;
}
return result;
};}
/**
* Defers executing the `func` function until the current call stack has cleared.
* Additional arguments will be provided to `func` when it is invoked.
*
* @static
* @memberOf _
* @category Functions
* @param {Function} func The function to defer.
* @param {...*} [arg] Arguments to invoke the function with.
* @returns {number} Returns the timer id.
* @example
*
* _.defer(function(text){ console.log(text); }, 'deferred');
*
*/
function defer(func){
if(!isFunction(func)){
throw new TypeError;
}
var args=slice(arguments, 1);
return setTimeout(function(){ func.apply(undefined, args); }, 1);
}
/**
* Executes the `func` function after `wait` milliseconds. Additional arguments
* will be provided to `func` when it is invoked.
*
* @static
* @memberOf _
* @category Functions
* @param {Function} func The function to delay.
* @param {number} wait The number of milliseconds to delay execution.
* @param {...*} [arg] Arguments to invoke the function with.
* @returns {number} Returns the timer id.
* @example
*
* _.delay(function(text){ console.log(text); }, 1000, 'later');
*
*/
function delay(func, wait){
if(!isFunction(func)){
throw new TypeError;
}
var args=slice(arguments, 2);
return setTimeout(function(){ func.apply(undefined, args); }, wait);
}
/**
* Creates a function that memoizes the result of `func`. If `resolver` is
* provided it will be used to determine the cache key for storing the result
* based on the arguments provided to the memoized function. By default, the
* first argument provided to the memoized function is used as the cache key.
* The `func` is executed with the `this` binding of the memoized function.
* The result cache is exposed as the `cache` property on the memoized function.
*
* @static
* @memberOf _
* @category Functions
* @param {Function} func The function to have its output memoized.
* @param {Function} [resolver] A function used to resolve the cache key.
* @returns {Function} Returns the new memoizing function.
* @example
*
* var fibonacci=_.memoize(function(n){
* return n < 2 ? n:fibonacci(n - 1) + fibonacci(n - 2);
* });
*
* fibonacci(9)
*
*
* var data={
* 'fred': { 'name': 'fred', 'age': 40 },
* 'pebbles': { 'name': 'pebbles', 'age': 1 }
* };
*
*
* var get=_.memoize(function(name){ return data[name]; }, _.identity);
* get('pebbles');
*
*
* get.cache.pebbles.name='penelope';
* get('pebbles');
*
*/
function memoize(func, resolver){
if(!isFunction(func)){
throw new TypeError;
}
var memoized=function(){
var cache=memoized.cache,
key=resolver ? resolver.apply(this, arguments):keyPrefix + arguments[0];
return hasOwnProperty.call(cache, key)
? cache[key]
: (cache[key]=func.apply(this, arguments));
}
memoized.cache={};
return memoized;
}
function once(func){
var ran,
result;
if(!isFunction(func)){
throw new TypeError;
}
return function(){
if(ran){
return result;
}
ran=true;
result=func.apply(this, arguments);
func=null;
return result;
};}
/**
* Creates a function that, when called, invokes `func` with any additional
* `partial` arguments prepended to those provided to the new function. This
* method is similar to `_.bind` except it does **not** alter the `this` binding.
*
* @static
* @memberOf _
* @category Functions
* @param {Function} func The function to partially apply arguments to.
* @param {...*} [arg] Arguments to be partially applied.
* @returns {Function} Returns the new partially applied function.
* @example
*
* var greet=function(greeting, name){ return greeting + ' ' + name; };
* var hi=_.partial(greet, 'hi');
* hi('fred');
*
*/
function partial(func){
return createWrapper(func, 16, slice(arguments, 1));
}
function partialRight(func){
return createWrapper(func, 32, null, slice(arguments, 1));
}
function throttle(func, wait, options){
var leading=true,
trailing=true;
if(!isFunction(func)){
throw new TypeError;
}
if(options===false){
leading=false;
}else if(isObject(options)){
leading='leading' in options ? options.leading:leading;
trailing='trailing' in options ? options.trailing:trailing;
}
debounceOptions.leading=leading;
debounceOptions.maxWait=wait;
debounceOptions.trailing=trailing;
return debounce(func, wait, debounceOptions);
}
/**
* Creates a function that provides `value` to the wrapper function as its
* first argument. Additional arguments provided to the function are appended
* to those provided to the wrapper function. The wrapper is executed with
* the `this` binding of the created function.
*
* @static
* @memberOf _
* @category Functions
* @param {*} value The value to wrap.
* @param {Function} wrapper The wrapper function.
* @returns {Function} Returns the new function.
* @example
*
* var p=_.wrap(_.escape, function(func, text){
* return ' ' + func(text) + ' ';
* });
*
* p('Fred, Wilma, & Pebbles');
*
*/
function wrap(value, wrapper){
return createWrapper(wrapper, 16, [value]);
}
function constant(value){
return function(){
return value;
};}
/**
* Produces a callback bound to an optional `thisArg`. If `func` is a property
* name the created callback will return the property value for a given element.
* If `func` is an object the created callback will return `true` for elements
* that contain the equivalent object properties, otherwise it will return `false`.
*
* @static
* @memberOf _
* @category Utilities
* @param {*} [func=identity] The value to convert to a callback.
* @param {*} [thisArg] The `this` binding of the created callback.
* @param {number} [argCount] The number of arguments the callback accepts.
* @returns {Function} Returns a callback function.
* @example
*
* var characters=[
* { 'name': 'barney', 'age': 36 },
* { 'name': 'fred', 'age': 40 }
* ];
*
*
* _.createCallback=_.wrap(_.createCallback, function(func, callback, thisArg){
* var match=/^(.+?)__([gl]t)(.+)$/.exec(callback);
* return !match ? func(callback, thisArg):function(object){
* return match[2]=='gt' ? object[match[1]] > match[3]:object[match[1]] < match[3];
* };
* });
*
* _.filter(characters, 'age__gt38');
*
*/
function createCallback(func, thisArg, argCount){
var type=typeof func;
if(func==null||type=='function'){
return baseCreateCallback(func, thisArg, argCount);
}
if(type!='object'){
return property(func);
}
var props=keys(func),
key=props[0],
a=func[key];
if(props.length==1&&a===a&&!isObject(a)){
return function(object){
var b=object[key];
return a===b&&(a!==0||(1 / a==1 / b));
};}
return function(object){
var length=props.length,
result=false;
while (length--){
if(!(result=baseIsEqual(object[props[length]], func[props[length]], null, true))){
break;
}}
return result;
};}
function escape(string){
return string==null ? '':String(string).replace(reUnescapedHtml, escapeHtmlChar);
}
function identity(value){
return value;
}
function mixin(object, source, options){
var chain=true,
methodNames=source&&functions(source);
if(!source||(!options&&!methodNames.length)){
if(options==null){
options=source;
}
ctor=lodashWrapper;
source=object;
object=lodash;
methodNames=functions(source);
}
if(options===false){
chain=false;
}else if(isObject(options)&&'chain' in options){
chain=options.chain;
}
var ctor=object,
isFunc=isFunction(ctor);
forEach(methodNames, function(methodName){
var func=object[methodName]=source[methodName];
if(isFunc){
ctor.prototype[methodName]=function(){
var chainAll=this.__chain__,
value=this.__wrapped__,
args=[value];
push.apply(args, arguments);
var result=func.apply(object, args);
if(chain||chainAll){
if(value===result&&isObject(result)){
return this;
}
result=new ctor(result);
result.__chain__=chainAll;
}
return result;
};}});
}
function noConflict(){
context._=oldDash;
return this;
}
function noop(){
}
/**
* Gets the number of milliseconds that have elapsed since the Unix epoch
* (1 January 1970 00:00:00 UTC).
*
* @static
* @memberOf _
* @category Utilities
* @example
*
* var stamp=_.now();
* _.defer(function(){ console.log(_.now() - stamp); });
*
*/
var now=isNative(now=Date.now)&&now||function(){
return new Date().getTime();
};
var parseInt=nativeParseInt(whitespace + '08')==8 ? nativeParseInt:function(value, radix){
return nativeParseInt(isString(value) ? value.replace(reLeadingSpacesAndZeros, ''):value, radix||0);
};
function property(key){
return function(object){
return object[key];
};}
function random(min, max, floating){
var noMin=min==null,
noMax=max==null;
if(floating==null){
if(typeof min=='boolean'&&noMax){
floating=min;
min=1;
}
else if(!noMax&&typeof max=='boolean'){
floating=max;
noMax=true;
}}
if(noMin&&noMax){
max=1;
}
min=+min||0;
if(noMax){
max=min;
min=0;
}else{
max=+max||0;
}
if(floating||min % 1||max % 1){
var rand=nativeRandom();
return nativeMin(min + (rand * (max - min + parseFloat('1e-' + ((rand +'').length - 1)))), max);
}
return baseRandom(min, max);
}
/**
* Resolves the value of property `key` on `object`. If `key` is a function
* it will be invoked with the `this` binding of `object` and its result returned,
* else the property value is returned. If `object` is falsey then `undefined`
* is returned.
*
* @static
* @memberOf _
* @category Utilities
* @param {Object} object The object to inspect.
* @param {string} key The name of the property to resolve.
* @returns {*} Returns the resolved value.
* @example
*
* var object={
* 'cheese': 'crumpets',
* 'stuff': function(){
* return 'nonsense';
* }
* };
*
* _.result(object, 'cheese');
*
*
* _.result(object, 'stuff');
*
*/
function result(object, key){
if(object){
var value=object[key];
return isFunction(value) ? object[key]():value;
}}
/**
* A micro-templating method that handles arbitrary delimiters, preserves
* whitespace, and correctly escapes quotes within interpolated code.
*
* Note: In the development build, `_.template` utilizes sourceURLs for easier
* debugging. See http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl
*
* For more information on precompiling templates see:
* http://lodash.com/custom-builds
*
* For more information on Chrome extension sandboxes see:
* http://developer.chrome.com/stable/extensions/sandboxingEval.html
*
* @static
* @memberOf _
* @category Utilities
* @param {string} text The template text.
* @param {Object} data The data object used to populate the text.
* @param {Object} [options] The options object.
* @param {RegExp} [options.escape] The "escape" delimiter.
* @param {RegExp} [options.evaluate] The "evaluate" delimiter.
* @param {Object} [options.imports] An object to import into the template as local variables.
* @param {RegExp} [options.interpolate] The "interpolate" delimiter.
* @param {string} [sourceURL] The sourceURL of the template's compiled source.
* @param {string} [variable] The data object variable name.
* @returns {Function|string} Returns a compiled function when no `data` object
* is given, else it returns the interpolated text.
* @example
*
*
* var compiled=_.template('hello <%=name %>');
* compiled({ 'name': 'fred' });
*
*
*
* _.template('<%- value %>', { 'value': ' |